Nov 10, 2011

How to access a control by using JavaScript


Reference the ClientID property (or UniqueID) of the control in the JavaScript.
protected void Page_Load(object sender, EventArgs e)
{
    Button btn= new Button();
    btn.ID = "btn5";
    btn.Attributes.Add("runat", "server");
    btn.Attributes.Add("onclick", "pop('" + btn.ClientID + "')");
    btn.Text = "Test";
    this.form1.Controls.Add(btn);
}
function pop(InputBoxID)
{
    var InputControl = document.getElementById(InputBoxID);
    alert(InputControl.value);
}
Or you can use the following method:
btn.Attributes.Add("onclick", "pop(this)");
function pop(InputBox)
{
    alert(InputBox.value);
}

Related posts:

0 comments:

Post a Comment

Your comments:

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More