How to trigger client script from server script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manu

    #1

    How to trigger client script from server script?

    In my ASPX code I would like to open a new window, send a message box,
    create an alert window etc. The logic when to do the above is
    implemented in the server side, as it is depended upon Database
    information. (i.e. open an alert window when a record was not found in
    the database.)
    As I know opening such windows can be done on the client side only.
    How can I trigger these scripts from the SERVER side?
    Is there an example explaining this?
  • Ignacio Machin

    #2
    Re: How to trigger client script from server script?

    Hi Manu,

    Well you have several options that are all based on the same idea, you have
    a server side control , a Literal to me more precise , where you pass the
    code or set the variables needed at the client, the value of this Text
    property goes unchanged to the client, therefore you can do something like:
    literal.Text= "<script> Alert('Hello'); </script>";
    this.Controls.A dd( literal);

    Now this is the basic idea, from there you have to code what you need, you
    can set a function in the OnLoad event of the Body that call a function ,
    and you use the literal to set a variable to decide what to do, etc

    Another idea without the use of the Literal control may be setting the value
    of OnLoad to one of several functions already defined in the HTML page, this
    is useful if you have a predefined number of messages that do not change
    ( like a not found message ) , for this you have to mark the Body with
    runat="server":
    <body ID="Body" runat="server">

    then in the server side you declare it like:
    protected HtmlGenericCont rol Body;

    and then add the correct function to the OnLoad using
    Body.Attributes .Add("OnLoad", "FunctionToCall ");


    Hope this help,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Manu" <ecy@bezeqint.n et> wrote in message
    news:a397ec0.03 09150249.6af266 03@posting.goog le.com...[color=blue]
    > In my ASPX code I would like to open a new window, send a message box,
    > create an alert window etc. The logic when to do the above is
    > implemented in the server side, as it is depended upon Database
    > information. (i.e. open an alert window when a record was not found in
    > the database.)
    > As I know opening such windows can be done on the client side only.
    > How can I trigger these scripts from the SERVER side?
    > Is there an example explaining this?[/color]


    Comment

    • Chris Hornberger

      #3
      Re: How to trigger client script from server script?

      Send the javascript to the client via Response.Write. ..

      string msg = "<script language=\"java script\">";
      msg += "alert('You r message here');";
      msg += "</script>";
      Response.Write( msg );

      ecy@bezeqint.ne t (Manu) wrote in message news:<a397ec0.0 309150249.6af26 603@posting.goo gle.com>...[color=blue]
      > In my ASPX code I would like to open a new window, send a message box,
      > create an alert window etc. The logic when to do the above is
      > implemented in the server side, as it is depended upon Database
      > information. (i.e. open an alert window when a record was not found in
      > the database.)
      > As I know opening such windows can be done on the client side only.
      > How can I trigger these scripts from the SERVER side?
      > Is there an example explaining this?[/color]

      Comment

      Working...