Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable Submit Button and validate inserted values during Postback
    primarykey
    data
    text
    <p>I've a Validate function and it returns true and false depending upon the inserted values. I want to validate as well as disable the submit button. for ex OnClientClick = "return Validate(this);" if it returns true, submit into database and disable submit for that period of time and if it is false disable submit and alert with the validate message.</p> <pre><code>&lt;script type="text/javascript"&gt; function Validate(b) { function stuff() { var temp = document.getElementById("&lt;%=txt_stuff.ClientID %&gt;").value; var val = /^[a-zA-Z0-9 ]+$/ if (temp == "") { alert("Please Enter Stuff"); return false; } else if (val.test(temp)) { return true; } else { alert("Name accepts only spaces and charcters"); return false; } } function price() { var temp2 = document.getElementById("&lt;%=txt_price.ClientID %&gt;").value; var val2 = /^[0-9 ]+$/ if (temp2 == "") { alert("Please Enter Price"); return false; } else if (val2.test(temp2)) { return true; } else { alert("Price accepts only Number"); return false; } } if (stuff() &amp;&amp; price()) { b.disabled = true; b.value = 'Submitting...'; return true; } else { return false; } } &lt;/script&gt; </code></pre> <p>Here is the button code</p> <pre><code> &lt;asp:Button ID="Button2" runat="server" Text="Add Record" OnClientClick = "return Validate(this)" onclick="Button2_Click" /&gt; </code></pre> <p>The button gets disabled but the value isn't submitted into the database and the button also doesn't get enabled again. What could be the reason?</p> <p>Database code is </p> <pre><code>protected void Button2_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(500); SqlConnection con = new SqlConnection(); con.ConnectionString = "Data Source=DTPXP-77A;Initial Catalog=practice;Integrated Security=true"; con.Open(); SqlCommand cmd = new SqlCommand("insert into expense values(@person,@item,@expdate,@price)", con); cmd.Parameters.Add("@person", SqlDbType.VarChar); cmd.Parameters.Add("@item", SqlDbType.VarChar); cmd.Parameters.Add("@expdate", SqlDbType.DateTime); cmd.Parameters.Add("@price", SqlDbType.Int); cmd.Parameters["@person"].Value = droplist_person.SelectedItem.ToString(); cmd.Parameters["@item"].Value = txt_stuff.Text; cmd.Parameters["@expdate"].Value = DateTime.Now.ToString(); cmd.Parameters["@price"].Value = txt_price.Text; cmd.ExecuteNonQuery(); InsertHistory(); Response.Redirect("Add.aspx"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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