0

I have a html button that calls an asp button to dopostback, but nothing happens.

<input type='button' value='click me' id='btntoClick'/>

<div id='divServerBtn' style='display:none'>
<asp:button ID='myButton' runat='server' onClick='myOnclickMethod'> </div>

my jquery:

$(function(){ 
  $("#btntoClick").on("click", function(){ $("#myButton").click(); })
});

OR

if I set the div to visible at run time, still clicking the button does nothing, it goes to codebehind but IsPostBack is false

$(function(){       
  $("#divServerBtn").attr("display", "");
});
Stephen
  • 1,532
  • 1
  • 9
  • 17

1 Answers1

0

Try something like this as a test, then modify your code accordingly. The main thing is to use OnClientClick, not OnClick. It is also important to include "return false;"

Your function:

    <script>
    function ShowMe() {
        $(function() {        
            $("#divServerBtn").show();
        });
    }
    </script>

Your aspx button and div example:

    <div id='divServerBtn' style='display:none'>Me</div>
    <br />
    <asp:Button ID="Button1" runat="server" OnClientClick="ShowMe(); return false;" Text="Button" OnClick="Button1_Click" UseSubmitBehavior="False" />
smoore4
  • 4,520
  • 3
  • 36
  • 55