Click here to Skip to main content
12,394,971 members (61,938 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Javascript
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:ImageButton ID="imgAuthorise" runat="server" ImageUrl="~/Images/Authorise.png" TabIndex="-1" ToolTip="Authorise" Visible="False" OnClientClick="return ToggleButton()" />
JavaScript Method

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 7-Aug-12 11:09am
amuneeb368
Updated 7-Aug-12 11:12am
Wes Aday104.2K
v2
Comments
   
Did you try to execute it under debugger? Do you have the JavaScript debugger, functional?
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
   
OP commented:

I have tried it in debugger, no joy. event on server side does not get fired.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

hiii,

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

<%@ 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>
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

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


Cheers
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100