how to check all textbox on click btnsave if there is no empty text box do something else message error that you have to need to fill empty textbox frist
i try this code
foreach (Control c in this.Controls)
{
if (c is TextBox)
{
TextBox textBox = c as TextBox;
if (textBox.Text == string.Empty)
{
textbox.text="please fill your empty textbox ";
}
else
{
// if my textbox all are fill i put my code to save data in datebase here
}
}
}
i try this code but it do nothing ????
Loading
Sanjeeb LenkaPosted Jul 19, 2013, 6:17 AM
protected void Button1_Click(object sender, EventArgs e)
{
CleartextBoxes(this);
}
public void CleartextBoxes(Control parent)
{
foreach (Control c in parent.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
if (((TextBox)(c)).Text == string.Empty)
{
Label1.Text = "text box is blank";
}
else
{
//Write code for insert the text value to database here
}
}
if (c.HasControls())
{
CleartextBoxes(c);
}
}
}
if any problem reply
alaaPosted Jul 19, 2013, 1:41 PM
Sanjeeb LenkaPosted Jul 19, 2013, 1:04 PM
alaaPosted Jul 19, 2013, 12:06 PM
Vishwas KadamannayaPosted Jul 19, 2013, 6:17 AM
you can add requiredfiledValidator to your textboxs and set CausesValidation of your button to true.