Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP Button OnClick Confirm Based On Other Variable?

Posted on 2012-04-10
4
Medium Priority
?
186 Views
Last Modified: 2012-04-28
I use the javascript:return on typical Gridview buttons. I have not used it on a common page button. I need to open a java Confirm window only if a flag is set like so:

private void checkBox1_OnCheckChanged(object sender, EventArgs e)
{
        Session["isChanges"] == true;
}

private void btnSearch(object sender, EventArgs e)
{
        if(Session["isChanges"] == true)
        {
             Session["isChanges"] = false; //reset flag
   
            //popup java confirm window
        }

        SaveChanges();
}
0
Comment
Question by:pointeman
[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
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 1200 total points
ID: 37829198
you can register client script block from code behind like this:-

// Form the script that is to be registered at client side.
       String scriptString = "<script language=JavaScript> function DoClick() {";
       scriptString += "alert('Are you sure you want to close me??');}<";
       scriptString += "/";
       scriptString += "script>";

           if(!this.IsClientScriptBlockRegistered("clientScript"))
              this.RegisterClientScriptBlock("clientScript", scriptString);

Open in new window

0
 

Author Comment

by:pointeman
ID: 37829808
Where do I place your code in my code example?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37829827
if(Session["isChanges"] == true)
        {
             Session["isChanges"] = false; //reset flag
   
            //place the code here....
        }
0
 

Author Comment

by:pointeman
ID: 37832385
I cannot get your code example to work dymanicaly. I'm now using button attributes in the Page_Load().

if(...)
    btnSearch.Attributes.Add("onclick", "return confirm('Are you sure you want to proceed?')");
else
    btnSearch.Attributes.Remove("onclick");
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

609 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