Alerting the user from code behind

Discussion in 'ASP .Net Building Controls' started by Peter Aitken, Jul 31, 2004.

  1. Peter Aitken

    Peter Aitken Guest

    I need to alert the user when code behind in a user control encounters
    certain data conditions. I'd like to do this with a MsgBox but I know that
    code behind cannot call this function, at least not directly. Is there a way
    to do this?

    --
    Peter Aitken

    Remove the crap from my email address before using.
     
    Peter Aitken, Jul 31, 2004
    #1
    1. Advertising

  2. Peter Aitken

    Peter Aitken Guest

    "Peter Aitken" <> wrote in message
    news:%...
    > I need to alert the user when code behind in a user control encounters
    > certain data conditions. I'd like to do this with a MsgBox but I know that
    > code behind cannot call this function, at least not directly. Is there a

    way
    > to do this?
    >
    > --


    To answer my own question

    Response.write("<script>alert("The message")</script">)


    --
    Peter Aitken

    Remove the crap from my email address before using.
     
    Peter Aitken, Aug 1, 2004
    #2
    1. Advertising

  3. Peter Aitken

    Adam Kinney Guest

    I would suggest using a Register method of the Page Class instead. You gain
    more control of where the javascript is added to the page and you ensure the
    javascript is only added once.

    RegisterStartupScript -
    http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterStartupScriptTopic.asp

    RegisterClientScriptBlock -
    http://msdn.microsoft.com/library/d...RegisterClientScriptBlockTopic.asp?frame=true


    Adam Kinney
    http://www.adamkinney.com


    "Peter Aitken" <> wrote in message
    news:%...
    > "Peter Aitken" <> wrote in message
    > news:%...
    > > I need to alert the user when code behind in a user control encounters
    > > certain data conditions. I'd like to do this with a MsgBox but I know

    that
    > > code behind cannot call this function, at least not directly. Is there a

    > way
    > > to do this?
    > >
    > > --

    >
    > To answer my own question
    >
    > Response.write("<script>alert("The message")</script">)
    >
    >
    > --
    > Peter Aitken
    >
    > Remove the crap from my email address before using.
    >
    >
     
    Adam Kinney, Aug 2, 2004
    #3
  4. Peter Aitken

    Peter Aitken Guest

    "Adam Kinney" <> wrote in message
    news:...
    > I would suggest using a Register method of the Page Class instead. You

    gain
    > more control of where the javascript is added to the page and you ensure

    the
    > javascript is only added once.
    >
    > RegisterStartupScript -
    >

    http://msdn.microsoft.com/library/d...mWebUIPageClassRegisterStartupScriptTopic.asp
    >
    > RegisterClientScriptBlock -
    >

    http://msdn.microsoft.com/library/d...RegisterClientScriptBlockTopic.asp?frame=true
    >
    >
    > Adam Kinney
    > http://www.adamkinney.com
    >
    >



    Thanks, Adam. When would you use the Client version versus the Startup
    version?

    --
    Peter Aitken

    Remove the crap from my email address before using.
     
    Peter Aitken, Aug 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    607
    Alphonse Giambrone
    Jun 28, 2003
  2. susie

    Sample for Alerting user

    susie, Dec 3, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    93
  3. Farrel Lifson

    RCAP - Common Alerting Protocl for Ruby

    Farrel Lifson, Nov 3, 2009, in forum: Ruby
    Replies:
    1
    Views:
    104
    Farrel Lifson
    Nov 3, 2009
  4. Farrel Lifson
    Replies:
    0
    Views:
    110
    Farrel Lifson
    Apr 6, 2011
  5. Laser Lips
    Replies:
    8
    Views:
    141
    Laser Lips
    Jul 6, 2010
Loading...

Share This Page