Solved

ASP Button OnClick Confirm Based On Other Variable?

Posted on 2012-04-10
4
167 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
  • 2
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 300 total points
Comment Utility
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
Comment Utility
Where do I place your code in my code example?
0
 
LVL 20

Expert Comment

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

Author Comment

by:pointeman
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

17 Experts available now in Live!

Get 1:1 Help Now