Note that there are some explanatory texts on larger screens.

plurals
  1. POErr raised on validation how can i exit
    primarykey
    data
    text
    <p>I have a certain webform that collects user information in my webpage when the user hits the </p> <p>save button it calls a function save() in my <strong>dbEngineClass</strong>.</p> <p>Now when the user enters duplicate data i raise a certain error and handle it in the web page </p> <p>to display a certain message box but after that i want it to exit the class and not do </p> <p>anything else</p> <p>but apparently it will continue the execution of the <strong>btnsave.click</strong> sub </p> <p>How can i exit the class or prevent the click method from continuing if an error is raised ?</p> <p>Here is My Code:<strong>This Is the Function That saves the info and raises the event</strong></p> <pre><code>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 </code></pre> <p><strong>And here is how i handle it in the web Page</strong></p> <pre><code>Private Sub MydbEngine_DuplicateErr() Handles MydbEngine.DuplicateErr Dim strMsg As String = "Duplicate Value exist" Dim lbl As New Label lbl.Visible = True lbl.Text = "&lt;script language='javascript'&gt;" &amp; Environment.NewLine _ &amp; "window.alert(" &amp; "'" &amp; strMsg &amp; "'" &amp; ")&lt;/script&gt;" Page.Controls.Add(lbl) End Sub conn.Close() End Sub </code></pre> <p>Now after this handler finishes i need it to exit and do not continue the btnSave.click </p> <p>handler that calls the <strong>SaveNewCustomer() sub</strong> since when it continues it clears all the </p> <p>data and i don't want that</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload