Solved

asp messagebox

Posted on 2011-09-30
20
340 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 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