Reputation: 2920
I dont know why linkbutton onclick event is not firing. 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. Kindly help me figure this out.
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. 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();
line.
This is beyond me. Help me out.
Upvotes: 1
Views: 1964
Reputation: 2920
So the problem seemed to be with JavaScript. Actually there was a button on my page with ID=submit
this was overriding submit()
function on the form, hence the error. This helped
Thumbs Up for Stackoverflow Community.
Upvotes: 1
Reputation: 826
Sorry if I can't comment due to low reputation points. I would like to know if you need CauseValidation set to false.
Try adding usesubmitbehavior="false".
Upvotes: 0