Solved

ASP Button OnClick Confirm Based On Other Variable?

Posted on 2012-04-10
4
181 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 300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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