alert in class library file

Posted by Ragha under C# on 4/14/2008 | Views : 7446 | Status : [Member] | Replies : 4
hi

i have a class library class(.cs) file

i would like to check a condition

depending on the condition if condition is met i would like to display an alert message otherwise else part to be executed


i have written some code


but no effect

if (condition)
{
string popupScript = "<script language='javascript'>" + "window.alert('Message'); </script>";
Page.RegisterStartupScript("PopupScript", popupScript);
//HttpContext.Current.Response.Write("<script>var agree =alert('Message');</script>");
//HttpContext.Current.Response.Write("<script>alert('Message')</script>");
}
else
{
do something
}


is this correct or please suggest someother solution


thanks




Responses

Posted by: Bubbly on: 2/20/2010 [Member] Bronze

Up
0
Down
Hello,

You can use Winforms namespace instead and use MessageBox for Alert message.

++
Thanks & Regards,
Deepika

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 4/14/2008 [Member] Starter

Up
0
Down
Hey

I tried your code in my Page_Load and its working for me.

    protected void Page_Load(object sender, EventArgs e)

{
bool b = true;
if (b)
{
string popupScript = "<script language='javascript'>" + "window.alert('Message'); </script>";
Page.RegisterStartupScript("PopupScript", popupScript);

}
else
{
b = false;
}
}


But notice that i wrote it inot my code behind file, Perhaps this will not work in class library as Page class is not accessible there, not sure. Why don't you try setting variable there and retrieve that variable and write the message into code behind after checking that variables?



Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ragha on: 4/14/2008 [Member] Starter

Up
0
Down
yes Raj


i too got in aspx page


but i want in .cs file


please any other solution


thanks


Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 4/14/2008 [Member] Starter

Up
0
Down
As suggested, you should get a flat set for a variable that you should return to the UI and in the UI you should check for that flag and render the script block.

Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response