ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Uncheck selected ASP.Net GridView CheckBox if Error occurs using jQuery AJAX<p>Hi&nbsp;Warren,</p> <p>To prevent CheckBox from remaining checked if RAISERROR event occurs you need to change the return type to string or int or as per any other type and and return the value based on the return type.</p> <p>Then in the ajax success function based on the return value uncheck the checkbox.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#39;.Mark&#39;).on(&#39;change&#39;, function () { var id = $(this).closest(&#39;tr&#39;).find(&#39;td&#39;).eq(0).html(); var checkbox = $(this).closest(&#39;tr&#39;).find(&#39;[id*=btnMark]&#39;); var Marked = $(this).closest(&#39;tr&#39;).find(&#39;[id*=btnMark]:checked&#39;).val() var LabelFullname = document.getElementById(&#39;&lt;%=LabelFullname.ClientID%&gt;&#39;).innerText; $.ajax({ type: &#34;POST&#34;, url: &#34;Default.aspx/Mark&#34;, data: &#34;{id:&#34; + id + &#34;,Marked:&#39;&#34; + Marked + &#34;&#39;, LabelFullname:&#39;&#34; + LabelFullname + &#34;&#39;}&#34;, contentType: &#34;application/json; charset=utf-8&#34;, dataType: &#34;json&#34;, error: function (jqXHR, textStatus, errorThrown) { alert(&#34;get session failed &#34; + errorThrown); }, success: function (response) { if (response.d == &#34;failed&#34;) { $(checkbox).prop(&#39;checked&#39;, false) } } }); }); }); &lt;/script&gt; &lt;asp:Label ID=&#34;LabelFullname&#34; runat=&#34;server&#34; Text=&#34;Test&#34; /&gt; &lt;asp:GridView runat=&#34;server&#34; ID=&#34;gvtfaLoan&#34; AutoGenerateColumns=&#34;false&#34;&gt; &lt;Columns&gt; &lt;asp:BoundField DataField=&#34;ID&#34; HeaderText=&#34;0. ID&#34; ShowHeader=&#34;false&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;ID&#34; /&gt; &lt;asp:TemplateField HeaderText=&#34;11. Mark&#34; HeaderStyle-Wrap=&#34;false&#34; SortExpression=&#34;Marked&#34;&gt; &lt;ItemTemplate&gt; &lt;asp:CheckBox ID=&#34;btnMark&#34; runat=&#34;server&#34; Checked=&#39;&lt;%# Eval(&#34;Marked&#34;) %&gt;&#39; CssClass=&#34;form-check-input Mark&#34; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">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(&#34;ID&#34;, typeof(int)), new System.Data.DataColumn(&#34;Marked&#34;, typeof(bool)) }); dt.Rows.Add(1, false); dt.Rows.Add(2, false); gvtfaLoan.DataSource = dt; gvtfaLoan.DataBind(); } } [System.Web.Services.WebMethod] public static string Mark(int id, string Marked, string LabelFullname) { try { int age = int.Parse(&#34;test&#34;); return &#34;success&#34;; } catch (Exception ex) { return &#34;failed&#34;; } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then Dim dt As Data.DataTable = New Data.DataTable() dt.Columns.AddRange(New Data.DataColumn() { New Data.DataColumn(&#34;ID&#34;, GetType(Integer)), New Data.DataColumn(&#34;Marked&#34;, GetType(Boolean))}) dt.Rows.Add(1, False) dt.Rows.Add(2, False) gvtfaLoan.DataSource = dt gvtfaLoan.DataBind() End If End Sub &lt;Services.WebMethod()&gt; Public Shared Function Mark(ByVal id As Integer, ByVal Marked As String, ByVal LabelFullname As String) As String Try Dim age As Integer = Integer.Parse(&#34;test&#34;) Return &#34;success&#34; Catch ex As Exception Return &#34;failed&#34; End Try End Function</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/ApNduVp.gif" alt="" width="248" height="181" /></span></strong></p>https://www.aspforums.net:443/Threads/141733/Uncheck-selected-ASPNet-GridView-CheckBox-if-Error-occurs-using-jQuery-AJAX/https://www.aspforums.net:443/Threads/141733/Uncheck-selected-ASPNet-GridView-CheckBox-if-Error-occurs-using-jQuery-AJAX/Wed, 26 Dec 2018 02:24:34 GMT