Problem in showing Alert Box [Solved]
-
That's odd. Where are you writing this code ? Not in a page class, I assume, otherwise the Response object would be there.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Hi, I am writting this code in a C# class. But i solved the above error by writting :
catch(System.Exception ex)
{
HttpContext.Current.Response.Write("<script>alert('" + ex.Message + "');</script>");
}But its not showing Alert Box on exception.
-
Hi, I am writting this code in a C# class. But i solved the above error by writting :
catch(System.Exception ex)
{
HttpContext.Current.Response.Write("<script>alert('" + ex.Message + "');</script>");
}But its not showing Alert Box on exception.
nagendrathecoder wrote:
But its not showing Alert Box on exception.
Are you sure code is hitting the exception?:confused:Put a break point and check that first.
Arun Jacob http://codepronet.blogspot.com/
-
nagendrathecoder wrote:
But its not showing Alert Box on exception.
Are you sure code is hitting the exception?:confused:Put a break point and check that first.
Arun Jacob http://codepronet.blogspot.com/
Yes it is showing exception. Its also going over that alert box code but still alert box is not displayed. If i am just writing the exception on page like
HttpContext.Current.Response.Write(ex.Message);
its showing the exception but not the alert box.
-
Yes it is showing exception. Its also going over that alert box code but still alert box is not displayed. If i am just writing the exception on page like
HttpContext.Current.Response.Write(ex.Message);
its showing the exception but not the alert box.
Use this.... Page page = HttpContext.Current.Handler as Page; if (page != null) { ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('Hi..')", true); }
-
Hi, I am writting this code in a C# class. But i solved the above error by writting :
catch(System.Exception ex)
{
HttpContext.Current.Response.Write("<script>alert('" + ex.Message + "');</script>");
}But its not showing Alert Box on exception.
nagendrathecoder wrote:
But i solved the above error by writting :
Yeah, that looks like it could work. However, it's bad form for your non presentation layer to be pumping out HTML. You'd do better to catch the exception in the presentation layer and put your code there.
nagendrathecoder wrote:
But its not showing Alert Box on exception.
Have you checked the HTML to make sure your javascript is being inserted ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Use this.... Page page = HttpContext.Current.Handler as Page; if (page != null) { ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('Hi..')", true); }
I tried but its showing error: "The name 'ScriptManager' does not exist in the current context"
-
I tried but its showing error: "The name 'ScriptManager' does not exist in the current context"
Everyone is assuming you're writing script inside your page. That you're not, is bad design. You should fix that, catch the exception in your presentation layer, and do it there. I agree, using the script manager is a good idea. It is an object on the page class, so you can access it that way.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
nagendrathecoder wrote:
But i solved the above error by writting :
Yeah, that looks like it could work. However, it's bad form for your non presentation layer to be pumping out HTML. You'd do better to catch the exception in the presentation layer and put your code there.
nagendrathecoder wrote:
But its not showing Alert Box on exception.
Have you checked the HTML to make sure your javascript is being inserted ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
ok, now i am passing my exception as a string to presentation layer and trying to show alert box there, but its still not working.
-
ok, now i am passing my exception as a string to presentation layer and trying to show alert box there, but its still not working.
OK, did you do the other stuff I suggested ? I agree with the person who said to use RegisterClientScriptBlock. Then you need to check to see if the script is being passed into the HTML or not. If it's not there, then that's your issue. if it is, you need to work out why it does not display ( I would have expected it to )
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hello All, I am creating a class in C# for some functionality and later consuming it in my ASP.Net application. I have written Try-Catch blocks in that class. If an exception occurs, i want to display some message to user in Alert Box. I am trying to generate alert box from below code
catch(System.Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}But its showing compile time error : "The name 'Response' does not exist in the current context" Am i missing something? Thanks, Nagendra.
modified on Wednesday, September 9, 2009 2:40 AM
I am getting this string as my script
string msg ="alert('Violation of PRIMARY KEY constraint 'PK_BOMDetail'. Cannot insert duplicate key in object 'dbo.BOMDetail'.\r\nThe statement has been terminated.');";
RegisterClientScriptBlock("Hello", msg);Its still not showing. :sigh:
-
I am getting this string as my script
string msg ="alert('Violation of PRIMARY KEY constraint 'PK_BOMDetail'. Cannot insert duplicate key in object 'dbo.BOMDetail'.\r\nThe statement has been terminated.');";
RegisterClientScriptBlock("Hello", msg);Its still not showing. :sigh:
Guess what, its worked. :) The single quotes was troubling me. Thanks for all your help.