How to prevent postback on asp button while displaying a popup using JQuery

后端 未结 3 375
感情败类
感情败类 2021-01-27 06:27

I have the following ItemTemplate in my GridView:


    

        
相关标签:
3条回答
  • 2021-01-27 06:31

    Put it out on the tag or <%: Html.BeginForm %> tag

    0 讨论(0)
  • 2021-01-27 06:41

    Actually you have not showed up the implementation of your method myfunction(), in case the myfunction() method have any syntactical error then the OnClientClick event will be void and it will post-back/submit the form to the server.

    Try to remove the call from OnClientClick and just implement your logic at jquery on click event by using class selector as follows

    $(document).ready(function () {
            $(".btnSearch").click(function (e) {
                e.preventDefault();
                alert($(this).val() + " Clicked"); // you can put your method mymethod() here 
                // you can put youe popup logic here
    
                return false; 
    
            });
        });
    

    You can also see this example of js fiddle

    0 讨论(0)
  • 2021-01-27 06:54
    OnClientClick="return myfunction(); 
    
    function myfunction(){
    // you can put youe popup logic here 
    
        return false;
    
    }
    

    Using like this your button never do post back.

    0 讨论(0)
提交回复
热议问题