Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
dear all,
i have write this code for alert in serverside but give me fololwing errors.

JavaScript
Response.Write("<script language='javascript' type='text/javascript'>alert('This EmailID Allready Exist. Please Enter valid EmailID')</script>")

Error message:-Sys.WebForms.PageRequestManagerParserErrorException: The message received
from the server could not be parsed. Common causes for this error are when the
response is modified by calls to Response.Write(), response Details: Error
parsing near '<script language='Ja'.

Thanks n regards,
Posted
Updated 24-Apr-12 2:14am
v4
Comments
Rahul Rajat Singh 24-Apr-12 8:35am    
This problem is because of escape characters. i tried putting the right thing here but the CP autoformat seems to be messing it up again. so lemme tell you

use @ character in the beginning of string starting with ". and inside that only use ' and not ". and it will work fine.
Mohamed Mitwalli 24-Apr-12 8:44am    
agree with you i face this problem , this will be useful too
Response.Write("<script>alert('This EmailID Allready Exist. Please Enter valid EmailID')</script>");
it will work fine .

You can't response.write literal values in asp.net. Back in the old days, folks would use response.write to create HTML in classic ASP.

The proper way to do it is to use onClientClick, which will fire your Javascript first, before firing a handler such as a postback event, that way you can cancel the postback if the Javascript doesn't like the value.

button.onClientClick = "alert('This EmailID Already Exist. Please Enter valid EmailID'; return false;)"


That will fire the message box in Javascript, but best practice is to actually write a more complex Javascript function, that will validate the data, and then fire the messagebox, and return true to fire the postback event, or false to cancel it.

One of the proper uses for response.write is to respond to a HTTP page request in code, and reply response.write( "Error 500" ).
 
Share this answer
 
v2
I believe all solution there Right
 
Share this answer
 
Try as
C#
Page.RegisterStartupScript("StatusMessage", "<SCRIPT LANGUAGE='JavaScript'>alert('This EmailID Allready Exist. Please Enter valid EmailID');</Script>");
 
Share this answer
 
Page.RegisterStartupScript("StatusMessage", "<SCRIPT LANGUAGE="'JavaScript'">alert('This EmailID Allready Exist. Please Enter valid EmailID');</Script>");


Use above or

C#
ScriptManager.RegisterStartupScript(this, GetType(), "msg", "alert('This EmailID Allready Exist. Please Enter valid EmailID');", true);
 
Share this answer
 
Comments
DINESH K MAURYA 24-Apr-12 7:26am    
thanks for
but this code not working in serverside
i have try this ...
please suggest me .
Mohamed Mitwalli 24-Apr-12 8:36am    
just write like this
Response.Write("<script>alert('This EmailID Allready Exist. Please Enter valid EmailID')</script>");
Hi,

Try this, just use GetType() in Page client script..

C#
this.Page.ClientScript.RegisterStartupScript(GetType(), "dd1", "<script language='javascript'>alert('This EmailID Allready Exist. Please Enter valid EmailID');</script>");


It may help you..
 
Share this answer
 
Hi ,
try this Note when i ADD Pre tags it make it like this language="'javascript'" and this will give error
Just Remove those "" from language='javascript'
C#
Response.Write("<script language='javascript' type='text/javascript'>alert('This EmailID Allready Exist. Please Enter valid EmailID')</script>"); 


OR
like this
C#
Response.Write("<script>alert('This EmailID Allready Exist. Please Enter valid EmailID')</script>"); 

Best regards
M.Mitwalli
 
Share this answer
 
v9
C#
Page.ClientScript.RegisterStartupScript(GetType(), "ScriptKey", "alert('" + strMsg + "')", true);

And if you are using ajax(script manager and update panal) then use this..

ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('" + strMsg + "');", true);
 
Share this answer
 
Try this one its may work...

string errormsg = "<script>alert('This EmailID Allready Exist. Please Enter valid EmailI')</script>";
            Label lblerror = new Label();
            lblerror.Text = errormsg;
            Page.Controls.Add(lblerror);


[edit] added code tags [/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900