Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

asp messagebox

Hey guys, i need to show a message box in my web app when hosted?

i have this c# code

 
protected void showMessageBox(string message)
    {
        string sScript;
        message = message.Replace("'", "");
        sScript = String.Format("alert('{0}');", message);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", sScript, true);
    }

Open in new window


now it just shows the ok button, i need it to show yes or no and if the user selects no it just close and if the user selects yes and want to code in c# to do a redirect and pass parameter, which i want to code in c#.

Please help...
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

i'm not sure whether you could use yes/no without a js library but you might try wuth confirm

HTH

Ivo Stoykov
ScriptManager.RegisterStartupScript(this, this.GetType(), "confirm", sScript, true);

Open in new window

Avatar of JCWEBHOST
JCWEBHOST

ASKER

ok how can i code so when the user clicks the yes or no button?
Avatar of Kiran Sonawane
Check this

protected void showMessageBox(string message)
    {
        string sScript;
        message = message.Replace("'", "");
        sScript = String.Format("confirm('{0}');", message);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", sScript, true);
    }

Open in new window

use a library like jQuery. here is a demo

HTH

Ivo Stoykov
that works and display the yes and no, is they way when the user clicks yes that i can code in c# for that button or javascript?
i need to code in c#
Yes you can do that

sScript = String.Format("if(confirm('{0}')) { alert('Code goes here if user click on YES');} else {alert('Code goes here if user click on NO/CANCEL');}", message);
this code fine:

protected void showMessageBox(string message)
    {
        string sScript;
        message = message.Replace("'", "");
        sScript = String.Format("confirm('{0}');", message);
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", sScript, true);
    }


now in c# code how do i code if the user click on yes or no?
can i have i redirect to a page if yes?

sScript = String.Format("if(confirm('{0}')) { alert('Code goes here if user click on YES');} else {alert('Code goes here if user click on NO/CANCEL');}", message);
You can not do this. You need write the code in javascript as I mentioned above
Yes you can redirect

sScript = String.Format("if(confirm('{0}')) { window.location='your_page.aspx';} else {alert('Code goes here if user click on NO/CANCEL');}", message);
ok how can i do a redirct in java when the user clicks the yes button?
and if the user select no nothing must happen
got an erorr:

rror: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.
Show your showMessageBox function
   protected void showMessageBox(string message)
    {
        string sScript;
        message = message.Replace("'", "");
        sScript = String.Format("if(confirm('{0}')) { window.location='/login/home.aspx';} else {}", message);  
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", sScript, true);
    }
Try below code. I am just checking the error you are getting is bocoz of "/' and then let me know
protected void showMessageBox(string message)
{
        string sScript;
        message = message.Replace("'", "");
        sScript = String.Format("if(confirm('{0}')) { window.location='home.aspx';} else {}", message);  
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", sScript, true);
}
still erorr :(
erorr here

sScript = String.Format("if(confirm('{0}')) { window.location='home.aspx';} else {}", message);  
ASKER CERTIFIED SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial