Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp messagebox

Posted on 2011-09-30
20
Medium Priority
?
371 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

824 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