Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a button (authorise) in master page, which raises event. Then based on child page, I authorise the ticket. However when someone clicks on authorise button, I have to confirm as well and then disable authorise button to avoid multiple clicks.

Here is HTML in masterpage

ASP.NET
<asp:ImageButton ID="imgAuthorise" runat="server" ImageUrl="~/Images/Authorise.png" TabIndex="-1" ToolTip="Authorise" Visible="False" OnClientClick="return ToggleButton()" />

JavaScript Method

JavaScript
function ToggleButton() {
            var button = document.getElementById(event.srcElement.id);
            var returnValue = true;

            if (button.disabled) {
            }

            else {
                var check = confirm('Are you sure that you want to authorise?');
                if (check) {
                     button.disabled = true;
                    returnValue = true;
                }
                else {
                     button.disabled = false;
                    returnValue = false;
                }
            }
            return returnValue;
        }

Now, if I comment lines with button.disabled. function returns proper value and child page executes event successfully. However, if I place button.disabled lines back, then child page does not subscribe to event.

Can anyone help me please?
Posted
Updated 7-Aug-12 11:12am
v2
Comments
Sergey Alexandrovich Kryukov 7-Aug-12 17:40pm    
Did you try to execute it under debugger? Do you have the JavaScript debugger, functional?
--SA

Hi!
Thanks for the help. I found solution
Check this link
It works perfectly in my situation.


Cheers
 
Share this answer
 
hiii,

this is your master page code where authorise button on master page hope this will ans.

XML
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <script type="text/javascript">
         function ToggleButton() {
             var button = document.getElementById('<%= imgAuthorise.ClientID %>');
             var returnValue = true;
             if (button.disabled) {
             }

             else {
                 var check = confirm('Are you sure that you want to authorise?');
                 if (check) {

                     returnValue = true;
                 }
                 else {

                     returnValue = false;
                 }
             }
             return returnValue;
         }


    </script>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">

    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ImageButton ID="imgAuthorise" runat="server" ImageUrl="~/Images/Authorise.png" TabIndex="-1" ToolTip="Authorise"  OnClientClick="return ToggleButton()" />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
v2
Comments
amuneeb 8-Aug-12 5:59am    
I cannot put authorise button in the child page. That totally makes masterpage useless. Masterpage is suppose to give you advantage of placing controls once. If I am placing button in child page. I will have to change every child page and I have around 50 child pages.
Either run it under debugger or sandwich in try-catch block to see what happens. Most likely, the button element is not found, and the attempt to dereference non-initialized object causes exception.

—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Aug-12 21:18pm    
OP commented:

I have tried it in debugger, no joy. event on server side does not get fired.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900