So after the message for exception is shown i want the user to be on the registration page so that he can enter a unique user id . How do i make sure that the user stays on the page and the next two lines are executed when the user id is unique?
Hi achuthan1988,
I suggest you to do like this.
catch(SqlException ex)
{
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User ID has to be Unique');", true);
}
and you may not need to use windows.location.href to redirect to the register page once again.
If the register is completed successfully, then please try the code
Sage Gu - MS...
Contributor
6693 Points
578 Posts
Microsoft
Re: Handling Unique key Exceptions.
May 11, 2012 08:51 AM|LINK
Hi achuthan1988,
I suggest you to do like this.
catch(SqlException ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User ID has to be Unique');", true); }and you may not need to use windows.location.href to redirect to the register page once again.
If the register is completed successfully, then please try the code
this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Register Successfully!');window.location.href='AnotherPage.aspx'", true);out of the try-catch block to another page.
However, it is not an efficient way to solve the problem by catching the exception.
Regards
Sage Gu - MSFT
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework