MessageBox Codebehind Parsing Javascript Errror?

I have a masterpages web .NET 3.5 and use Ajax UpdatePanel. I've tried either code examples to create a MessageBox popup window from C# codebehind via Javascript, but always recieve a page error:

[code]
Response.Write("<script language='javascript'>alert('Success');</script>");

[error]
Error parsing near '<script language='ja'.

--or--

[code]
Response.Write("<script language=Javascript>alert('Success');</script>");

[Error]
Error parsing near '<script language=Jav'.
pointemanAsked:
Who is Participating?
 
burakiewiczConnect With a Mentor Commented:
try this
ScriptManager.RegisterStartupScript(updatePanel1, updatePanel1.GetType, "Message", "alert('Success');", true);
0
 
jmwheelerCommented:
Use burakiewicz's suggestion.  You cannot use Response.Write in a asynchronous call.  It will always cause an error.
0
 
pointemanAuthor Commented:
.. has invalid arguments...
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "Message", "alert('Success');", true);
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
burakiewiczConnect With a Mentor Commented:
change this
UpdatePanel1.GetType
to
UpdatePanel1.GetType()
0
 
burakiewiczCommented:
sorry about that
0
 
pointemanAuthor Commented:
I would also like to be able to call a javascript from a script folder as well.

protected void Button1_Click(object sender, EventArgs e)
{
      call ~/script/JScript.js function MessageBoxAlert(textstring)
}
 
0
 
burakiewiczCommented:
if the script is registered on the page, you just call it like normal
then
string strExample=string.Concat("MessageBoxAlert('",txt1.Text,"');";
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "Message",strExample,true);
0
 
pointemanAuthor Commented:
That works:

ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "Message", "alert('Success');", true);  
0
 
pointemanAuthor Commented:
Q. Do all javascript alert windows look like a small IE window like this code initializes?
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "Message", "alert('Success');", true);  
 
0
 
burakiewiczCommented:
i think all javascript alerts look like that. They might vary by browser.  If you want a custom one, you can use the ajax modalpopupextender and create a custom looking one with a panel
0
 
pointemanAuthor Commented:
The ASP.NET Ajax Tool Kit?
0
 
burakiewiczCommented:
yeah, there is a control called the modal popup extender
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/
0
 
pointemanAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.