I have a asp:Button and asp:Textbox on Default.aspx page
Code is as below:
<asp:Button ID="Button1" runat="server" Text="Save" Width="80px" CommandName="Update"
OnClientClick="EnableDdlCompany();saveButtonClick();" CommandArgument="Save" OnClick="btnSave_Click"/>
<asp:TextBox ID="txtBarcodeNumber" runat="server" MaxLength="11" Width="230px"
Text='<%# Bind("BarcodeNo") %>' Display="None"
OnTextChanged="TextChanged" AutoPostBack="true"></asp:TextBox>
On button click, I want to call a javascript code to check that If the entered BarCode Number in Textbox already exist in Database, then show an alert "Number already exist" else allow user to save and navigate to Default2.aspx
I can able to do the same checking on TextBox OnTextChanged
event using c# code, as below:
protected void TextChanged(object sender, EventArgs e)
{
TextBox txtbarcode = fvIPRForm.FindControl("txtbarcodenumber") as TextBox;
if (txtbarcode.Text.Length > 0 && txtbarcode.Text.Length < 11)
{
string error = "The Barcode Number " + txtbarcode.Text + " is invalid, the barcode length must be 11 character.";
ScriptManager.RegisterStartupScript(this, typeof(string), "Successful", "alert('" + error + "');", true);
txtbarcode.Text = "";
}
string requestID = Request.QueryString["requestID"];
Guid? reqid = null;
if (requestID != null) reqid = new Guid(requestID);
if (!IPRRequest.IsValidBarcodeTest(reqid, txtbarcode.Text)) // checking of Barcode already exist
{
string content = "Barcode Number already exist in system database.";
ScriptManager.RegisterStartupScript(this, typeof(string), "Successful", "alert('" + content + "');", true);
txtbarcode.Text = "";
}
}
here, IPRRequest
is the class/.dll file name and IsValidBarcodeTest
is a function defined in the class file
but same checking I tried using the c# code on button's OnClick="btnSave_Click"
event, but dont know why this event is not firing, I guess due to CommandArgument
on button, but I am not sure.
Thatswhy I want to achieve it using Javascript.
Please help me to do the same using Javascript.
Thanks in advance.