Results 1 to 11 of 11

Thread: OnClientCLick problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    OnClientCLick problem

    Hi,

    I have a Button control when clicked fires some javascript which sets a DIV tag visibility to true. This all works fine, but what it doean't do is fire the serverside OnClick button event?

    My Javascript code:
    Code:
     
    <script type="text/javascript">
            function showSending(e)
            {
                linkID = document.getElementById(e)
                linkID.disabled = true;  
                
                linkID = document.getElementById("sending")
                linkID.style.visibility = "visible";    
                
            }
    </script>
    My HTML Code:

    Code:
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnSending" runat="server" Text="Sending" OnClientClick="return showSending(this.id)" OnClick="btnSending_Click" />
            <div id="sending" style="border: solid 1px green; padding: 5px; width:55px; font-family:Verdana; font-size:12px; visibility:hidden;">Sending..</div>    
        </div>
        </form>
    My OnClick event:

    Code:
    protected void btnSending_Click(object sender, EventArgs e)
        {
            // Do some stuff here
        }
    So once the div tag visibility is set i then want the button event to fire?

  2. #2
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    Re: OnClientCLick problem

    try changing

    OnClientClick="return showSending(this.id)"
    to
    OnClientClick="showSending(this.id)"

    at a guess this is a file upload message so that should work.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: OnClientCLick problem

    Unfortunately that doens't work. Once the button is clicked the onClick event still isn't being fired.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: OnClientCLick problem

    This is a message that should appear after a file is attached to an message then emailed.

    I just need a message to appear after the button click. ANy idea's how to get the server side code to fire?

  5. #5
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: OnClientCLick problem

    If the source of the submit is disabled, i.e. your button, the page won't submit. Simply delaying the disable for a tad may work:

    Code:
    function showSending(button) {
    	window.setTimeout("button.disabled = true", 50);
    	
    	var linkID = document.getElementById("sending");
    	linkID.style.visibility = "visible";
    	return true;
    }
    </script>
    
    <asp:Button ID="btnSending" runat="server" Text="Sending" OnClientClick="return showSending(this)" OnClick="btnSending_Click" />
    <div id="sending" style="border: solid 1px green; padding: 5px; width:55px; font-family:Verdana; font-size:12px; visibility:hidden;">Sending..</div>

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: OnClientCLick problem

    I tried this but i get the following error:

    'Microsoft JScript runtime error: 'button' is undefined'

  7. #7
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: OnClientCLick problem

    The OnClientClick property changed to "return showSending(this)"

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: OnClientCLick problem

    I couldn't get it working the way i wanted it to so i had to set the button visibility to hidden once it was clicked.

    It does the same job which is preventing the user from clicking the button again so i'm not complaining.

    Thanks.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: OnClientCLick problem

    am I missing something or is showsending JS function not returning a value, which would make it return false always?

  10. #10
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: OnClientCLick problem

    Quote Originally Posted by kleinma
    am I missing something or is showsending JS function not returning a value, which would make it return false always?
    Originally, yes, but the version I posted was explicit in its return

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: OnClientCLick problem

    Didn't see your post there. At least we are on the same thought

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width