Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to clear the Text box when using Page Methods in asp.net
    text
    copied!<p>I have been struggling with .net PageMethods. I have a text box and would like to clear it if the value returned from database call is invalid or its not in the table, now there is a javascript that shows the popup message but fails to clear the field. Here is my code.</p> <pre><code>aspx code: asp:TextBox name="LoanNumber" ID="LoanNumber" runat="server" size="18" style="font-size: 9pt" ValidationGroup="requiredCheck" onchange="javascript:SetFocus();loanCheckup();resetOnChange();" MaxLength="10" ToolTip="Enter a Loan Number" AutoPostBack="false"&gt;&lt;/asp:TextBox&gt; &lt;asp:RequiredFieldValidator ID="reqLoanNumExists" runat="server" ControlToValidate="LoanNumber" Display="Dynamic" ErrorMessage="Required Loan Number" SetFocusOnError="true" ValidationGroup="requiredCheck"&gt;Required! &lt;/asp:RequiredFieldValidator&gt; &lt;asp:RegularExpressionValidator ID="reqLoanNumber" ControlToValidate="LoanNumber" ValidationExpression="\d+" Display="Static" EnableClientScript="true" SetFocusOnError="true" ErrorMessage="Accepts Numbers Only!" runat="server"&gt; &lt;/asp:RegularExpressionValidator&gt; </code></pre> <p>Page method (code behind) [WebMethod]<br> public static string getRowValue(string loanNum) {</p> <pre><code> string result = ""; string tmpResultPass = ""; string tmpResultFail = ""; // doing all db connections here try { if (cmdGetLoanNum.Connection.State == ConnectionState.Closed) { cmdGetLoanNum.Connection.Open(); } tmpResultPass = cmdGetLoanNum.ExecuteScalar().ToString(); tmpResultPass = tmpResultPass + "Is Valid"; return tmpResultPass ; } catch (Exception ex) { string msg = ex.StackTrace.ToString(); tmpResultFail= loanNum + " The Existing Loan Number entered does not appear to be an active loan number. Please confirm that the value was entered correctly! "; return tmpResultFail; } finally { cmdGetLoanNum.Connection.Close(); cmdGetLoanNum.Dispose(); myConnection.Dispose(); } </code></pre> <p>MY java script:</p> <pre><code> function loanCheckup() { // var txtLoanNum = document.getElementById('&lt;%=LoanNumber.ClientID %&gt;').value; var txtLoanNum = document.getElementById('LoanNumber').value; //return Regex.IsMatch(txtLoanNum, "^-?\d*[0-9]?(|.\d*[0-9]|,\d*[0-9])?$"); PageMethods.getRowValue(txtLoanNum, successLoan,failLoan); } function successLoan(tmpResultPass) { alert(tmpResultPass); } function failLoan(tmpResultFail ) { alert(tmpResultFail); document.getElementById('LoanNumber').value = ""; } </code></pre> <p>Now when an exception is caught, tmpResultFail will appear, but the next line to clear the text field never gets executed. I have script manager with enable pagemethods = true. Everything works except clearing the textbox field. Any help is appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload