-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Pandurang_Nayak
Message 2 in Discussion
For adding client-side attributes (such as onclick, onmouseover, etc.) for any
ASP.NET server control, you have to use the control.Attributes.Add(attribute,
script-to-run) The script-to-run could be inline script or a JavaScript
function name. If it is the latter, you have to write the JavaScript function
within <SCRIPT> </SCRIPT> tags. You can also "generate" JavaScript from the
server side. Create a string that contains the script and then use the
Page.RegisterClientScriptBlock to inject that script into the page. Here's an
example of what you are trying to achieve: C# code: In Page_Load:
checkbox1.Attributes.Add("onclick", "enableTB()"); StringBuilder enableTB =
new StringBuilder(String.Empty); enableTB.AppendLine("function enableTB() {");
enableTB.AppendLine("if(document.forms[0]." + checkbox1.UniqueID +
".checked)"); enableTB.AppendLine("{ document.forms[0]." + textBox1.UniqueID +
".enabled = true;"); enableTB.AppendLine("}}");
Page.RegisterClientScriptBlock("enableTB", "<script>" + enableTB() +
"</script>"; ----- Note that the control.UniqueID is a safe way of doing
it, because sometimes in case of a Grid, Repeater, ASCX control, etc. HTML
controls get renamed by ASP.NET automatically to ensure that they have unique
names. UniqueID gets you that unique name that is generated by ASP.NET. Hope
that helps! There is also an excellent MSDN article on client script support
in ASP.NET 2.0. Check it out.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]