[英]LinkButton click event not firing asp.net
I dont know why linkbutton onclick event is not firing.我不知道为什么 linkbutton onclick 事件没有触发。 I have tried rewriting the code.
我试过重写代码。 I have tried to redirect directly on button click function.
我试图直接重定向按钮点击功能。 I have tried setting a break point inside
dashbut_Click()
on redirectUser()
line but it never reaches there.我尝试在
dashbut_Click()
内的redirectUser()
行上设置一个断点,但它从未到达那里。 Kindly help me figure this out.请帮我解决这个问题。
HTML: HTML:
<li><asp:LinkButton ID="dashbut" runat="server"
CausesValidation="false"
OnClick="dashbut_Click"
Text="Dashboard">
<img src="images/dash.png" height="25" width="25" class="fa fa-tachometer" /><span> Dashboard</span>
</asp:LinkButton>
</li>
Code Behind:背后的代码:
protected void dashbut_Click(object sender, EventArgs e)
{
//Response.Redirect("~/Views/Portal/AdminDashboard.aspx");
redirectUser();
}
private void redirectUser()
{
string myConnection = dbController.connectionString;
SqlConnection conn = new SqlConnection(myConnection);
string userCheckQuery = "SELECT UserType from tblUsers where ID = '" + USERid + "'";
SqlCommand cmd1 = new SqlCommand(userCheckQuery, conn);
conn.Open();
bool userType = (bool)cmd1.ExecuteScalar();
conn.Close();
if (userType == true)
{
Response.Redirect("~/Views/Portal/AdminDashboard.aspx");
}
else if (userType == false)
{
Response.Redirect("~/Views/Portal/Dashboard.aspx");
}
}
EDIT:编辑:
It seems that the LinkButton click event is not firing because of a JS Error.由于 JS 错误,LinkButton 单击事件似乎没有触发。 I dont know how that is related but when I click on the button and view the error on browser Inspect Element I see the following TypeError.
我不知道这是如何相关的,但是当我单击按钮并在浏览器检查元素上查看错误时,我看到以下类型错误。
Uncaught TypeError: theForm.submit is not a function
at __doPostBack (NewArtist.aspx:63)
at <anonymous>:1:1
This is the script:这是脚本:
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
Error is on theForm.submit();
错误出现在
theForm.submit();
line.线。
This is beyond me.这超出了我的范围。 Help me out.
帮帮我。
So the problem seemed to be with JavaScript.所以问题似乎出在 JavaScript 上。 Actually there was a button on my page with
ID=submit
this was overriding submit()
function on the form, hence the error.实际上,我的页面上有一个
ID=submit
按钮,它覆盖了表单上的submit()
函数,因此出现错误。 This helped Thumbs Up for Stackoverflow Community.这有助于为 Stackoverflow 社区竖起大拇指。
Sorry if I can't comment due to low reputation points.抱歉,如果我因为声望低而无法发表评论。 I would like to know if you need CauseValidation set to false.
我想知道您是否需要将 CauseValidation 设置为 false。
Try adding usesubmitbehavior="false".尝试添加 usesubmitbehavior="false"。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.