I am using asp.net 3.5 with c#. In my project i do some javascript
validation and some code in the button event to redirect the page to
another. But as i click the button it shows the javascript alert
message but at the same time it redirect to another page. I want to
verifying all the alert message and if there is no alert then it
redirect to the another page.

My javascript coding is

function Validate()
     {
                if(document.getElementById("<%=txtEmailid.ClientID
%>").value=="")
        {
            alert("EMAIL ID CAN NOT BE BLANK");
                document.getElementById("<%=txtEmailid.ClientID%>").focus();
            return false;
        }
}
<asp:ImageButton ID="ImageButton2" runat="server" Height="28px"
                         ImageUrl="~/PHOTO/Continue.gif"
Width="121px"
                         onclick="ImageButton2_Click"
OnClientClick="return Validate()/>


At first i have tried the above to call the function in
OnclientClick . but as it not works so i did the follow

protected void Page_Load(object sender, EventArgs e)
    {


    ImageButton2.Attributes.Add("onclick", "return Validate()");
    }


protected void ImageButton2_Click(object sender, ImageClickEventArgs
e)
    {
        some Sql queries and connection are here.............
        try
            {
                conn.Open();
                added = cmd.ExecuteNonQuery();
                Session["userid"]=uniqueid.ToString();
                Response.Redirect("HomePageComplete.aspx",true);
            }
            catch (Exception err)
            {
                lblCharMessage.Text = err.Message;
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
         }
   }

but still i get the problem............pls guide me.....


Reply via email to