Reputation: 8980
I'm trying to do a Response.Write
to pop up a Javascript error message when the script reaches my catch
block in my ASPX page (not in a code behind or a class).
Here is the code:
catch (Exception ex)
{
Response.Write("<script language=javascript>alert('ERROR');</script>");
//System.Windows.Forms.MessageBox.Show(ex.ToString());
}
The error message I get is:
} expected
No idea why it's telling me I need a }
. Everything has been closed, when I remove/comment out that line and put something else, I don't get any errors so obviously, it's not like I'm missing a closing }
somewhere...
Why is this happening??
Upvotes: 1
Views: 6053
Reputation: 22084
Problem is you probably have this statement enveloped in
<script type="text/c#">
</script>
So the
</script>
in statement below is taken as ending the C# script block
Response.Write("<script language=javascript>alert('ERROR');</script>");
I see two options - move this logic to codebehind or escape the script to something like
Response.Write("<script language=javascript>alert('ERROR');" + "<" + "/" + "script>");
Upvotes: 2
Reputation: 26209
I think you are missing single quote near language attribute, Try This:
Response.Write("<script language='javascript'>alert('ERROR');</script>");
Upvotes: 0
Reputation: 5876
If I were you, I would use RegisterScriptBlock. please read the text and the example. I am certainly sure that is what you need
Upvotes: 0