Problem with alert message

Discussion in 'ASP .Net' started by Vivian, Jun 28, 2006.

  1. Vivian

    Vivian Guest

    I've created a web page with ASP .NET and C#. Say my aspx filename is
    "WebForm1.aspx", I have created another C# file named "Details.cs".

    My problem is I want to prompt an alert message from both WebForm1.cs and
    Details.cs, WebForm1.cs works fine, but no message can be shown from
    Details.cs. The two files are in the same namespace with different class.
    I've referred to WebForm1.cs.

    The following is my code :

    Namespace = "Test"

    WebForm1.cs
    ===========
    inside class WebForm1

    public void PrintMsg(string key, string msg)
    {
    this.Page.RegisterClientScriptBlock(key, "<script
    type='text/javascript'>alert('" + msg + "');</script>");
    }

    Details.cs
    =======
    inside class detailscode

    private void PrintMessage(string key, string msg)
    {
    Test.WebForm1 oForm = new Test.WebForm1();
    oForm.PrintMsg(key, msg);
    }
     
    Vivian, Jun 28, 2006
    #1
    1. Advertising

  2. This is wrong approach. It wont show the alert message.

    Basically, the RegisterClientScriptBlock method just registers the
    script while rendering the page. In this case, first time when the
    webform loads it won't display the message. But, if you refresh the page
    again by pressing f5 it will display the alert box.

    Let me know if you are looking for the same or you want something else.

    -
    Vadivel Kumar
    http://vadivelk.net

    Vivian wrote:
    > I've created a web page with ASP .NET and C#. Say my aspx filename is
    > "WebForm1.aspx", I have created another C# file named "Details.cs".
    >
    > My problem is I want to prompt an alert message from both WebForm1.cs and
    > Details.cs, WebForm1.cs works fine, but no message can be shown from
    > Details.cs. The two files are in the same namespace with different class.
    > I've referred to WebForm1.cs.
    >
    > The following is my code :
    >
    > Namespace = "Test"
    >
    > WebForm1.cs
    > ===========
    > inside class WebForm1
    >
    > public void PrintMsg(string key, string msg)
    > {
    > this.Page.RegisterClientScriptBlock(key, "<script
    > type='text/javascript'>alert('" + msg + "');</script>");
    > }
    >
    > Details.cs
    > =======
    > inside class detailscode
    >
    > private void PrintMessage(string key, string msg)
    > {
    > Test.WebForm1 oForm = new Test.WebForm1();
    > oForm.PrintMsg(key, msg);
    > }
    >
    >
     
    Vadivel Kumar, Jun 28, 2006
    #2
    1. Advertising

  3. Vivian

    subhashiniRuckmani

    Joined:
    Jul 4, 2007
    Messages:
    2
    problem in alert message

    Hai friends

    I am very new to .net. I want to display the alert message from the class file.
    This class file is called in the Default.cs. can any one help me in this.

    Thanks in advance.
     
    subhashiniRuckmani, Jul 4, 2007
    #3
    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. Tony Girgenti

    Javascript alert message problem

    Tony Girgenti, Oct 4, 2006, in forum: ASP .Net
    Replies:
    22
    Views:
    2,070
    Laurent Bugnion
    Oct 16, 2006
  2. Mersh
    Replies:
    0
    Views:
    524
    Mersh
    Mar 13, 2007
  3. Ganesh
    Replies:
    0
    Views:
    585
    Ganesh
    Jun 29, 2007
  4. Tony Girgenti

    Javascript alert message problem

    Tony Girgenti, Oct 4, 2006, in forum: ASP .Net Building Controls
    Replies:
    12
    Views:
    238
    Laurent Bugnion
    Oct 16, 2006
  5. Tony Girgenti

    Javascript alert message problem

    Tony Girgenti, Oct 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    12
    Views:
    265
    Laurent Bugnion
    Oct 16, 2006
Loading...

Share This Page