Forum guidelines
  • Home
  • »
  • .NET 5.0
  • »
  • How to use ScriptManager.RegisterStartupScript in C#
How to use ScriptManager.RegisterStartupScript in C#
Posted By Santhonabin on 22 Feb 2011
  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.

void Button1_Click(object sender, EventArgs e)




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


Re: How to use ScriptManager.RegisterStartupScript in C#
Posted By Madhu K 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

Re: How to use ScriptManager.RegisterStartupScript in C#
Posted By Jaganathan Bantheswaran on 22 Feb 2011  

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');");
    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.


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.