I have a werbsite in ASP.NET using C# for CodeBehind. My JavaScript alert did fire where I had the ASP page list the C# as CodeFile. I have changed ASP to CodeBehind and now none of the JavaScript will fire. Below is the line of code.
Response.Write("<script langauge=\"javascript\">alert(\"Information has been saved!\");</script>");
This is on the button Click event.
I even created a class for a Static Alert but that wont fire. I debugged and put a break on the line but it returns no error just steps right through it. Any thoughts?
You may want to consider using just Javascript to handle this - unless you have specific reasons for performing a server-side hit. You could even handle a simple alert like this just using the onclickclick property of your button:
<asp:Button ID="Button1" runat="server" onclientclick="alert('Information has been saved!');" Text="Button" />
The first mehtod you suplied, same problem it wont fire.
The clientclick will work, but I am strill scratching my head why the other ways it wont work. I made an Alert class for the javascript see below. This doesnt work either.
// Assembly Referencesusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
namespace Solution_Vis_Log
{
publicstaticclassAlert
{
publicstaticvoid Show(string message)
{
string cleanMessage = message.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
Page page = HttpContext.Current.CurrentHandler asPage;
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}
}
}
}
DaBolander
Member
23 Points
17 Posts
Response.Write Java Alert not firing
Jan 16, 2013 05:41 PM|LINK
I have a werbsite in ASP.NET using C# for CodeBehind. My JavaScript alert did fire where I had the ASP page list the C# as CodeFile. I have changed ASP to CodeBehind and now none of the JavaScript will fire. Below is the line of code.
Response.Write("<script langauge=\"javascript\">alert(\"Information has been saved!\");</script>");
This is on the button Click event.
I even created a class for a Static Alert but that wont fire. I debugged and put a break on the line but it returns no error just steps right through it. Any thoughts?
Rion William...
All-Star
27894 Points
4616 Posts
Re: Response.Write Java Alert not firing
Jan 16, 2013 05:46 PM|LINK
Try using this within your code-behind click event for your button :
protected void Button1_Click(object sender, EventArgs e) { Response.Write("<script type='text/javascript'>alert('Information has been saved!');</script>"); }ASPX Page Markup
You may want to consider using just Javascript to handle this - unless you have specific reasons for performing a server-side hit. You could even handle a simple alert like this just using the onclickclick property of your button:
<asp:Button ID="Button1" runat="server" onclientclick="alert('Information has been saved!');" Text="Button" />DaBolander
Member
23 Points
17 Posts
Re: Response.Write Java Alert not firing
Jan 16, 2013 06:07 PM|LINK
The first mehtod you suplied, same problem it wont fire.
The clientclick will work, but I am strill scratching my head why the other ways it wont work. I made an Alert class for the javascript see below. This doesnt work either.
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: Response.Write Java Alert not firing
Jan 16, 2013 06:11 PM|LINK
Hi,
Try this line -
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
DaBolander
Member
23 Points
17 Posts
Re: Response.Write Java Alert not firing
Jan 16, 2013 06:29 PM|LINK
Figured it out. I have a "Response.Redirect" after the JavaScript. The page was terminating before the JS fired.