protected void Page_Load(object sender, EventArgs e)
{
panel4radio1.Attributes.Add("onClick", "Hidecontrols()");
This is a great way to assign javascript functionality to my radio button. This doesn't however actually execute the javascript. I would like to do both - execute javascript such as hiding a label from the server side during a page load or another event and then assign javascript functionality to a control to show the label on the client side without another trip to the server. How do you execute javascript functionality at the server within code behind? Using the example, I would like to run the Hidecontrols() function on pageload.
Amit ChoudharyPosted Mar 25, 2011, 8:12 AM
You can't force a click event of client side to execute from the server side. But there's a trick you can perform this rather than using "onclick" use "Onload" and use ClientScript.RegisterStartupScript();
This execute the javascript code as soon the script renders to the client page.
Thanks.
VikramPosted Mar 21, 2011, 1:54 PM
protected void Page_Load(object sender, EventArgs e)
{
panel4radio1.Attributes.Add("onClick", "Hidecontrols()");
ScriptManager.RegisterClientScriptBlock(this, GetType(), "HideControl", "return Hidecontrols();", true);
}
Hope this will help you.
Regards,
Vikram