Dear Friends,
I have placed some design & code of my example. Please go throw these.
Design is:
Select Your State : <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlState_SelectedIndexChanged"
Height="35px" Width="325px">
Select your City : <asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True" Height="35px" Width="325px">
select your Image : <asp:FileUpload ID="FileUpload1" runat="server" />
Enter your Email : <asp:TextBox ID="txtEmail" runat="server" Height="30px" Width="320px">
Enter your Mobile : <asp:TextBox ID="txtMobile" runat="server" Height="30px" Width="320px">
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
Text="Submit" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
ShowSummary="False" />
C# Code behind as:
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtEmail.Text) && string.IsNullOrEmpty(txtMobile.Text))
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('please enter your email or mobile.')", true);
}
else
{
if (FileUpload1.PostedFile.ContentLength != 0)
{
string strimage = @"~\Images\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(strimage));
String strInsert = "insert into Table1(State,City,Image,Email,Mobile)values('" + ddlState.SelectedItem.Text + "','" + ddlCity.SelectedItem.Text + "','" + strimage + "', '" + txtEmail.Text + "','" + txtMobile.Text + "')";
SqlCommand cmd = new SqlCommand(strInsert, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Your form has been submitted Successfully')", true);
lblDisplay.Text = "";
}
catch (SqlException ex)
{
}
finally
{
con.Close();
}
}
}
}
Now my problem is when ever user didn't select any mobile & email, it will show error message as 'please enter your email or mobile' on message box. This time i got the major problem, i.e the hole page is refreshed and already selected image also refreshed, this user again must need to chosen the image again & again. I don't want to refresh the selected image even i got error message on mobile & email.
Please ASAP give me your suggestions. Thanks in advance.