Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

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...
0
JCWEBHOST
Asked:
JCWEBHOST
  • 11
  • 7
  • 2
1 Solution
 
Ivo StoykovCommented:
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

0
 
JCWEBHOSTAuthor Commented:
ok how can i code so when the user clicks the yes or no button?
0
 
Kiran SonawaneProject LeadCommented:
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

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Ivo StoykovCommented:
use a library like jQuery. here is a demo

HTH

Ivo Stoykov
0
 
JCWEBHOSTAuthor Commented:
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?
0
 
JCWEBHOSTAuthor Commented:
i need to code in c#
0
 
Kiran SonawaneProject LeadCommented:
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);
0
 
JCWEBHOSTAuthor Commented:
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?
0
 
JCWEBHOSTAuthor Commented:
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);
0
 
Kiran SonawaneProject LeadCommented:
You can not do this. You need write the code in javascript as I mentioned above
0
 
Kiran SonawaneProject LeadCommented:
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);
0
 
JCWEBHOSTAuthor Commented:
ok how can i do a redirct in java when the user clicks the yes button?
0
 
JCWEBHOSTAuthor Commented:
and if the user select no nothing must happen
0
 
JCWEBHOSTAuthor Commented:
got an erorr:

rror: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.
0
 
Kiran SonawaneProject LeadCommented:
Show your showMessageBox function
0
 
JCWEBHOSTAuthor Commented:
   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);
    }
0
 
Kiran SonawaneProject LeadCommented:
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);
}
0
 
JCWEBHOSTAuthor Commented:
still erorr :(
0
 
JCWEBHOSTAuthor Commented:
erorr here

sScript = String.Format("if(confirm('{0}')) { window.location='home.aspx';} else {}", message);  
0
 
Kiran SonawaneProject LeadCommented:
Ok no worries.
Try this
in you c# code

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

Open in new window


In you aspx page within head tag
<script>
 function ShowAlert(msg)
{
   if (confirm(msg))
{
 window.location='/login/home.aspx';

}
}
</script>

Open in new window



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 11
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now