Solved

asp messagebox

Posted on 2011-09-30
20
344 Views
Last Modified: 2012-05-12
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
Comment
Question by:JCWEBHOST
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
  • 2
20 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36890235
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
 

Author Comment

by:JCWEBHOST
ID: 36890242
ok how can i code so when the user clicks the yes or no button?
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890273
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 36890296
use a library like jQuery. here is a demo

HTH

Ivo Stoykov
0
 

Author Comment

by:JCWEBHOST
ID: 36890299
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
 

Author Comment

by:JCWEBHOST
ID: 36890307
i need to code in c#
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890402
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
 

Author Comment

by:JCWEBHOST
ID: 36890406
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
 

Author Comment

by:JCWEBHOST
ID: 36890411
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
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890414
You can not do this. You need write the code in javascript as I mentioned above
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890421
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
 

Author Comment

by:JCWEBHOST
ID: 36890422
ok how can i do a redirct in java when the user clicks the yes button?
0
 

Author Comment

by:JCWEBHOST
ID: 36890427
and if the user select no nothing must happen
0
 

Author Comment

by:JCWEBHOST
ID: 36890432
got an erorr:

rror: Sys.WebForms.PageRequestManagerServerErrorException: Input string was not in a correct format.
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890436
Show your showMessageBox function
0
 

Author Comment

by:JCWEBHOST
ID: 36890437
   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
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36890442
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
 

Author Comment

by:JCWEBHOST
ID: 36890445
still erorr :(
0
 

Author Comment

by:JCWEBHOST
ID: 36890453
erorr here

sScript = String.Format("if(confirm('{0}')) { window.location='home.aspx';} else {}", message);  
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36890470
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question