I'm using twitter bootstrap in my application. i gave e.preventDefault for link button in $(document).ready(), but it is not working.
Here is my code:
Master page:
<a id="lnkLogout" href="javascript:void(0);" onclick="PageLogout();"><i class="icon-off"></i>Logout</a>
<asp:Button ID="btnLogout" OnClick="btnLogout_Click" runat="server" class="hidden" />
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$('#lnkLogout').click(function (e) { e.preventDefault(); });
});
function PageLogout() {
$("#btnLogout").click();
}
</script>
MasterPage.aspx.cs :
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
Response.Redirect("~/SampleWindowCloser.htm");
}
SampleDefaultPage.aspx :
<div class="row-fluid">
<div class="form-horizontal">
<h4 class="header blue bolder smaller">
Contact</h4>
<div class="control-group">
<label for="form-field-email" class="control-label">
Email</label>
<div class="controls">
<input type="text" style="width:200px;" data-val="true"
data-val-required="Mobile Number is required."
id="txtEmail">
<div class="space-3">
</div>
<span data-valmsg-replace="true" data-valmsg-for="txtEmail"
class="field-validation-valid text-warning red"></span>
</div>
</div>
<div class="control-group">
<label for="form-field-website" class="control-label">
Phone Number</label>
<div class="controls">
<input type="text" style="width:200px;"
id="txtPhno">
</div>
</div>
</div>
I have given txtEmail as mandatory field. if i left that field blank and click on Logout button in Master page, it says txtEmail is required. i dint do any validation in Logout onclick event. I have given preventDefault for Logout link. But still facing an issue. I should be able to logout even though txtEmail is left blank.
Thank you all in advance for your response.