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);
> }
>
>