Search This Blog

Saturday, December 15, 2007

Retrive ASP.NET Object value using javascript

I have a checkbox name Checkbox2 runat server, if we try to get value by calling ID= Checkbox2 using javascipt, javascript error: Object not found, this is because server side ID is different with the client side ID. Client side ID for this object is Checkbox2.ClientID.

For example, i need to pass Checkbox2 value to a javascript function during page load, this is what i do.

protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterStartupScript("Onload", "<script language='javascript'>fnCheck('" + Checkbox2.ClientID +"');</script>");
}

fnCheck is a javascript function that i already define some where.

No comments: