Wednesday, June 24, 2009

Access Text Box in ASP using Java Script

Access Java Script using ASP.NET 

Assume that you have a java script file callled sample.js
in the file

function display() {
     var TextBox = document.getElementById(
"TxtID");
    TextBox.value = "Hello";
}

In the Aspx Page

protected void Page_Load(object sender, EventArgs e)
        {
          
            ClientScriptManager script = Page.ClientScript;
            if (!script.IsClientScriptIncludeRegistered("ScriptInFile"))
            {
                script.RegisterClientScriptInclude("ScriptInFile", "
sample.js");
            }
       }

Assume you want to call the function on the onload event , then
in the body tag used Onload=display()

Note:-
Sometime this may not be worked. because the problem of the text box id. ASP generete ID for text box. then what you have to do is run the aspx page ones and get the text box id using view sourse. then replace TxtID that.

Post a Comment