How do i show popup error messsage when textbox is empty
I want to use this code below to show user that the recipt textbox is empty but the button OnSave is showing error
see link for the complete code
<div class="form-group-inner">
<div class="row">
<div class="">
<div class="input-group mg-b-pro-edt">
<span class="input-group-addon"><i class="fa fa-sticky-note-o" aria-hidden="true"></i></span>
<asp:TextBox ID="txtrecipt" runat="server" CssClass="form-control" placeholder="Recipt" ReadOnly="True"></asp:TextBox>
</div>
</div>
</div>
</div>
protected void OnSave(object sender, EventArgs e)
{
if (Page.IsValid)
{
if (txtrecipt.Text == "")
{
ScriptManager.RegisterClientScriptBlock(OnSave, this.GetType(), "alert", "<script>alert('Enter Quantity Ordered ... !!')</script>", false);
}
else
{
// lblMessage2.Text = "";
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("Item"), new DataColumn("Price"), new DataColumn("Quantity") });
foreach (Control c in ph1.Controls)
{
if (c.GetType().Name.ToLower() == "usercontrol_ascx")
{
UserControl uc = (UserControl)c;
TextBox tbItem = uc.FindControl("txtItem") as TextBox;
TextBox tbPrice = uc.FindControl("txtPrice") as TextBox;
TextBox tqty = uc.FindControl("txtQuantity") as TextBox;
if (!string.IsNullOrEmpty(tbItem.Text.Trim()) && !string.IsNullOrEmpty(tbPrice.Text.Trim()) && !string.IsNullOrEmpty(tqty.Text.Trim()))
{
dt.Rows.Add(tbItem.Text.Trim(), tbPrice.Text.Trim(), tqty.Text.Trim());
if (Convert.ToInt32(tqty.Text.Trim()) > 0)
{
int availableQuantity = Convert.ToInt32(GetAvailableQuantity(tbItem.Text.Trim()));
if (Convert.ToInt32(tqty.Text.Trim()) > availableQuantity)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('No of Quantity entered is not available in Stock')", true);
}
else
{
int inserted = Insert(tbItem.Text.Trim(), tbPrice.Text.Trim(), tqty.Text.Trim());
if (inserted > 0)
{
UpdateStock(tbItem.Text.Trim(), tqty.Text.Trim());
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Data Submitted Successfully ... !!')", true);
}
}
}
}
}
}
// BindGridID();
}
}
}