I have a certain webform that collects user information in my webpage when the user hits the
save button it calls a function save() in my dbEngineClass.
Now when the user enters duplicate data i raise a certain error and handle it in the web page
to display a certain message box but after that i want it to exit the class and not do
anything else
but apparently it will continue the execution of the btnsave.click sub
How can i exit the class or prevent the click method from continuing if an error is raised ?
Here is My Code:This Is the Function That saves the info and raises the event
Public Sub SaveNewCustomer(ByVal Name As String, ByVal Tel1 As String, ByVal Tel2 As String, ByVal Email As String, ByVal Address As String, ByVal Coupon As String, ByVal Location As String, ByVal ParamLangaugeID As String, ByVal UserName As String)
Dim UserNameID As Integer = GetUserNameID(UserName)
conn = New SqlConnection(My.Settings.CustomerInfoNayefPc)
conn.Open()
cmd = New SqlCommand(String.Format("Insert into tblCustomerInfo (Name,Tel1,Tel2,Email,Address,CouponNo,Location,LangaugeID,UserNameID) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},{8})", Name, Tel1, Tel2, Email, Address, Coupon, Location, ParamLangaugeID, UserNameID))
cmd.Connection = conn
Try
cmd.ExecuteNonQuery()
Catch CouponNosqlexc As SqlException
RaiseEvent DuplicateErr()
End Try
And here is how i handle it in the web Page
Private Sub MydbEngine_DuplicateErr() Handles MydbEngine.DuplicateErr
Dim strMsg As String = "Duplicate Value exist"
Dim lbl As New Label
lbl.Visible = True
lbl.Text = "<script language='javascript'>" & Environment.NewLine _
& "window.alert(" & "'" & strMsg & "'" & ")</script>"
Page.Controls.Add(lbl)
End Sub
conn.Close()
End Sub
Now after this handler finishes i need it to exit and do not continue the btnSave.click
handler that calls the SaveNewCustomer() sub since when it continues it clears all the
data and i don't want that