I’m completely new to working with JavaScript in ASP .NET so bear with me.
Say I have the following:
protected void btnCreateReplication_Click(object sender, EventArgs e)
{
try
{
doSomething();
}
catch (Exception ex)
{
//How do I display the error? I know if I were in WinForms, I could just do this:
MessageBox.Show(ex.Message);
}
}
First question:
- Should I put all of my JavaScript code in a .js file in my ASP .NET solution?
- If so, how do I call an alert message from the .js file?
- If not, how do I call an alert message instead of the MessageBox.Show?
You’ll have to use the
Page.ClientScript.RegisterClientScriptBlockmethod.RegisterClientScriptBlocktakes a type, a key to see if the script block is already registered, the script, and a boolean indicating whether the method should add thescripttags, or if you’re string script variable already includes them.