We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

MessageBox Codebehind Parsing Javascript Errror?

pointeman
pointeman asked
on
Medium Priority
1,090 Views
Last Modified: 2012-05-06
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'.
Comment
Watch Question

try this
ScriptManager.RegisterStartupScript(updatePanel1, updatePanel1.GetType, "Message", "alert('Success');", true);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Use burakiewicz's suggestion.  You cannot use Response.Write in a asynchronous call.  It will always cause an error.

Author

Commented:
.. has invalid arguments...
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "Message", "alert('Success');", true);
change this
UpdatePanel1.GetType
to
UpdatePanel1.GetType()
sorry about that

Author

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)
}
 
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);

Author

Commented:
That works:

ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "Message", "alert('Success');", true);  

Author

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);  
 
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

Author

Commented:
The ASP.NET Ajax Tool Kit?
yeah, there is a control called the modal popup extender
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/

Author

Commented:
Thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.