Monday, April 5, 2010

register the JavaScript function at Code-Behind in ASP .NET

There are two ways you can register javascript from codebehind.

First: You can use the RegisterScript method

this.Page.ClientScript.RegisterStartupScript(this.GetType(),"alert","alert(‘hello’);",true);

Second: You can use the Literal Control

private void Button2_Click(object sender, System.EventArgs e)
{
    string str;
    str="<script language='JavaScript'>"; 
    str+="selectRange()";
  str+="<script>";
    Literal1.Text=str;
}

No comments:

Post a Comment