__doPostBack()函数不起作用(asp.net) [英] __doPostBack() function isn't working (asp.net)

查看:105
本文介绍了__doPostBack()函数不起作用(asp.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从JS代码触发按钮事件.但是JS函数reg()中的doPostBack没有指向c#代码.请告诉我怎么了. 这是我的代码:

I am trying to trigger button event from the JS code. But doPostBack in JS function reg() is not directing to the c# code. Please tell me what's wrong. Here is my code:

<script>
        function reg() {
            var name = document.getElementById('name').value;
            var id = document.getElementById('cnic').value;
            var age = document.getElementById('age').value;
            var ph = document.getElementById('phone').value;
            var pas = document.getElementById('pass').value;
            if (id == '' || pas == '' || age == '' || ph == '' || pas == '')
                window.alert("Write all fields");
            else {
                __doPostBack('<%= Button1.UniqueID%>','')
            }
        }
    </script>  


 <div >
       <asp:Button id="Button1" OnClientClick="reg()" runat="server" Text="Submit"/>
    </div>

以下是与按钮关联的服务器端c#函数:

Here is the server side c# function associated with the button:

 protected void Btn_Click(object sender, EventArgs e)
    {
        Button clickedButton = (Button)sender;
        clickedButton.Text = "...button clicked...";
    }

注意:在else块中,我希望reg()函数重定向到Btn_Click函数.

Note: In else block, I want reg() function to redirect to the Btn_Click function.

推荐答案

自从我这样做已经有一段时间了,但是我认为它应该是服务器ID,而不是按钮的客户端ID.

It's been a while since I did this, but I think it needs to be the server Id, not client id of the button.

 __doPostBack('<%= button1.UniqueID%>','')

这篇关于__doPostBack()函数不起作用(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆