Problem with alert message

V

Vivian

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

Vadivel Kumar

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
 
Joined
Jul 4, 2007
Messages
2
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top