Solved

asp messagebox

Posted on 2011-09-30
20
341 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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