Hi smile,
I checked your code it's working, please see in below screenshot.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript">
$(function () {
$('[id*=txtObtain]').on("blur", function () {
var totalMarks = $("#txtTotal").val();
if (parseInt($(this).val()) > parseInt(totalMarks)) {
alert('Obtain Marks should be less than Total Marks');
$(this).val('');
$(this).focus();
}
});
});
</script>
<div class="table-responsive">
Total Marks:
<asp:TextBox ID="txtTotal" runat="server" />
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" Class="table table-striped table-bordered table-hover"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="100px" DataField="AdmissionNo" HeaderText="Reg No." />
<asp:BoundField ItemStyle-Width="70px" DataField="ReferenceNo" HeaderText="Ref No." />
<asp:BoundField ItemStyle-Width="200px" DataField="SName" HeaderText="Student Name" />
<asp:BoundField ItemStyle-Width="200px" DataField="FName" HeaderText="Father Name" />
<asp:BoundField ItemStyle-Width="70px" DataField="FPhone" HeaderText="Phone No." />
<asp:BoundField ItemStyle-Width="100px" DataField="SubjectName" HeaderText="Subject" />
<asp:TemplateField>
<HeaderTemplate>
Obtain</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtObtain" runat="server" class="form-control" Text="0"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button Text="Save" runat="server" OnClick="Save" />
</div>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] { new System.Data.DataColumn("AdmissionNo", typeof(string)),
new System.Data.DataColumn("ReferenceNo", typeof(string)),
new System.Data.DataColumn("SName", typeof(string)),
new System.Data.DataColumn("FName", typeof(string)),
new System.Data.DataColumn("FPhone", typeof(string)),
new System.Data.DataColumn("SubjectName", typeof(string)) });
dt.Rows.Add("A101", "1", "Khan", "Mudassar", "1464646", "ASP");
dt.Rows.Add("A102", "2", "Mathew", "Suzain", "4898546546", "JAVA");
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
}
protected void Save(object sender, EventArgs e)
{
//Write Insert Code
ScriptManager.RegisterStartupScript(this, this.GetType(), "CropImage", "alert('Record saved successfully.');", true);
}
Screenshot
IE
Chrome