Solved

asp messagebox

Posted on 2011-09-30
20
337 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now