Dynamically Disable an ASP.NET Control Client-Side

I wrote a control today to dynamically disable an ASP.NET control from the client - with NO POSTBACKS. It's actually pretty slick. All you do is drop the control on your form, and run ONE line in your if (!IsPostBack) section (oh, and for now, a simple JS function in your ascx/aspx - though you could just as easily inject that directly on the page too with a literal control).

I'll post it soon - faster if someone asks for it. :)

posted @ Wednesday, March 15, 2006 9:34 PM

Print

Comments on this entry:

# re: Dynamically Disable an ASP.NET Control Client-Side

Left by Ofer at 5/3/2006 12:02 PM
Gravatar
I would like to look at that code.I have a case when I need to disable one text box when the other text box as value. And enable both when there is nothing there. I wrote a code that doing it my only problem is when i select the text in the text box and delete it both text boxes should be enabled but it is not the case i have to click on the text box I just deleted and then I can focus on the other one. The code look like that.......

function disableAsp()
{
if(document.forms[0].elements['TextBox1'].value.length > 0)
{
document.forms[0].elements['TextBox2'].disabled = true;
document.forms[0].elements['TextBox2']
}
else if (document.forms[0].elements['TextBox2'].value.length > 0)
{

document.forms[0].elements['TextBox1'].disabled = true;
}
else
{
document.forms[0].elements['TextBox1'].disabled = false;
document.forms[0].elements['TextBox2'].disabled = false;
}
}


and to call this function::::::

TextBox1.Attributes.Add("onclick","javascript:disableAsp()");
TextBox1.Attributes.Add("onkeydown","javascript:disableAsp()");

TextBox2.Attributes.Add("onclick","javascript:disableAsp()");
TextBox2.Attributes.Add("onkeydown","javascript:disableAsp()");


Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345