-3

I am trying to add a javascript in to asp.net code behind page in c#.

I found some answers from this site and I have implemented that but still I am not able to call a function from ScriptManager.RegisterClientScriptBlock().

Please check my code;

protected void Page_Load(object sender, EventArgs e)
{
    string myScriptValue = "function callMe() {alert('You pressed Me!');}";
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", myScriptValue, true);
}

Please help me how to get the callMe() funtion in Page_Load().

2
  • 1
    Possible duplicate of add client script to asp.net page dynamically Commented Jul 31, 2017 at 14:37
  • 1
    You should user ScriptManager.RegisterStartupScript instead of ScriptManager.RegisterClientScriptBlock Commented Jul 31, 2017 at 14:37

1 Answer 1

0

You need to call the function callMe(); in aspx since Page_Load is the first to run before loading javascripts in the webpage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.