Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in showing Alert Box [Solved]

Problem in showing Alert Box [Solved]

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-nettoolsquestion
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Christian Graus

    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.

    N Offline
    N Offline
    nagendrathecoder
    wrote on last edited by
    #3

    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.

    A C 2 Replies Last reply
    0
    • N nagendrathecoder

      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.

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #4

      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/

      N 1 Reply Last reply
      0
      • A Arun Jacob

        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/

        N Offline
        N Offline
        nagendrathecoder
        wrote on last edited by
        #5

        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.

        Y 1 Reply Last reply
        0
        • N nagendrathecoder

          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.

          Y Offline
          Y Offline
          yesu prakash
          wrote on last edited by
          #6

          Use this.... Page page = HttpContext.Current.Handler as Page; if (page != null) { ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('Hi..')", true); }

          N 1 Reply Last reply
          0
          • N nagendrathecoder

            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.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #7

            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.

            N 1 Reply Last reply
            0
            • Y yesu prakash

              Use this.... Page page = HttpContext.Current.Handler as Page; if (page != null) { ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('Hi..')", true); }

              N Offline
              N Offline
              nagendrathecoder
              wrote on last edited by
              #8

              I tried but its showing error: "The name 'ScriptManager' does not exist in the current context"

              C 1 Reply Last reply
              0
              • N nagendrathecoder

                I tried but its showing error: "The name 'ScriptManager' does not exist in the current context"

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #9

                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.

                1 Reply Last reply
                0
                • C Christian Graus

                  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.

                  N Offline
                  N Offline
                  nagendrathecoder
                  wrote on last edited by
                  #10

                  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.

                  C 1 Reply Last reply
                  0
                  • N nagendrathecoder

                    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.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #11

                    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.

                    1 Reply Last reply
                    0
                    • N nagendrathecoder

                      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

                      N Offline
                      N Offline
                      nagendrathecoder
                      wrote on last edited by
                      #12

                      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:

                      N 1 Reply Last reply
                      0
                      • N nagendrathecoder

                        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:

                        N Offline
                        N Offline
                        nagendrathecoder
                        wrote on last edited by
                        #13

                        Guess what, its worked. :) The single quotes was troubling me. Thanks for all your help.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups