Forum guidelines
  • Home
  • »
  • .NET 5.0
  • »
  • How to use ScriptManager.RegisterStartupScript in C#
AuthorQuestion
How to use ScriptManager.RegisterStartupScript in C#
Posted on: 22 Feb 2011
Hi
  Pls tell me Step by step that how to use ScriptManager.RegisterStartupScript.

and also pls check following statement usage is correct or not. if not correct means pls tell the correct one.


protected
void Button1_Click(object sender, EventArgs e)


{

ScriptManager1.RegisterStartupScript(Page,Page.GetType(),

}

"alert", "<script language='javascript' type='text/javascript'>alert('page saved successfully');window.location='Exporttoword.aspx';</script>", false);

 

AuthorReply
Re: How to use ScriptManager.RegisterStartupScript in C#
Posted on: 22 Feb 2011  
ScriptManager1.RegisterStartupScript adds the script block to the page and registers the control that is in the update panel.
Check the link how to use

http://www.dotnetcurry.com/ShowArticle.aspx?ID=200


Re: How to use ScriptManager.RegisterStartupScript in C#
Posted on: 22 Feb 2011  
Hi,

You can try out this. It works fine.

protected void Page_Load(object sender, EventArgs e)
{
    lblDisplayDate.Text = System.DateTime.Now.ToString("T");
}
 
protected void btnPostback_Click(object sender, EventArgs e)
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"<script language='javascript'>");
    sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");
    sb.Append(@"lbl.style.color='red';");
    sb.Append(@"</script>");
 
    if (!ClientScript.IsStartupScriptRegistered("JSScript"))
    {
        ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
    }
}

While clicking the Postback button the date label color will be changed as Red.
Let me know if you have doubt.

Hope  this helps you. !


Mark as "This is correct Answer", if it helps you.
Employers - Post Free Jobs

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.