Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript function
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 12:09pm
amuneeb368
Edited 7-Aug-12 12:12pm
Wes Aday94.3K
v2
Comments
Sergey Alexandrovich Kryukov at 7-Aug-12 17:40pm
   
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
Sergey Alexandrovich Kryukov at 7-Aug-12 21:18pm
   
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 at 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
0 Sergey Alexandrovich Kryukov 144
1 Sascha Lefévre 100
2 OriginalGriff 90
3 Abhinav S 84
4 Maciej Los 84
0 Sergey Alexandrovich Kryukov 6,578
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Abhinav S 2,358
4 Maciej Los 2,352


Advertise | Privacy | Mobile
Web03 | 2.8.150414.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2015
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