Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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.
Posted
Comments
Member 10021658 7-Aug-14 7:17am    
please any one help me.
Member 10021658 7-Aug-14 8:07am    
hi friends,

am waiting for solution, please any one could help me.
VishwaKL 10-Aug-14 23:01pm    
hold the selected image path in some variable and assign back on page reload.I feel when your error pop up comes that time page is posting back, add Page.Ispostback condition in page load event. try both condition

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900