ASP.NET Form View IF on upgrade

I want to run an if if before updating the form view; if yes, then ... "message" and cancel the update request if you do not continue the update request.

I tried this, but I get "obeject instance not set to null instance ......" on the first line of the if? and the item is updated independently.

Private Sub FormView2_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView2.ItemUpdating
    Dim status As TextBox = FormView1.FindControl("ApprovalStatusTextBox")


    If status.Text = "approved" Or "denied" Then
        e.Cancel = True
        lblupdaterequest.Text = "you cannot update this request as it has already been responded to"
    Else
        HolidayDetailsdatasource.Update()
    End If

      

Did anyone know it was better to achieve something like this?

exact error:

   System.NullReferenceException was unhandled by user code
   Message=Object reference not set to an instance of an object.
   Source=WebApplication1
   StackTrace:
   at WebApplication1.HolidayApprovalDetails.DetailsView1_ItemUpdating(Object sender, DetailsViewUpdateEventArgs e) in line 32
   at System.Web.UI.WebControls.DetailsView.OnItemUpdating(DetailsViewUpdateEventArgs e)
   at System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation)
   at System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
   at System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e)
   at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   at System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e)
   at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
   at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

      

+3


source to share


2 answers


I can at least see that you are retrieving the TextBox status value from " FormView1 " while your ItemUpdating is referencing " FormView2 ".

After changing this setting, try adding a message box before the if to make sure you get the value you want:



MsgBox(status.Text)

      

Hope this helps you solve your problem.

+2


source


If status IsNot Nothing AndAlso (status.Text = "approved" OrElse status.Text = "denied") Then

      



+1


source







All Articles