View State


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: View State

  1. #1
    phillip Guest

    View State


    Here's my problem. I have a form that updates a database. This happens when
    you click a link that says update. When you click this link, the current
    data is displayed in this form. I want to be able to make adjustments to
    data that's displayed in the form and then submit the form and update the
    database. What's occuring is when I submit the form, the displayed data is
    switch back to it's previous state and that is what is sent to the database.
    Therefore no changes or made. This is what appears to be happening. I've
    disabled Viewstate at the control level and at the page level and it doesn't
    change anything. I think that's the way it goes with text boxes anyway when
    you post a page to itself. Below is a snippet of the code. Anyone have any
    idea how to bet this?

    Private Sub btnsave_ServerClick(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles btnsave.ServerClick Dim eventConnection
    As OleDbConnection Dim eventCommand = New OleDbCommand() Dim
    strInsert As String eventConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
    Source=C:\eventlog.mdb") eventConnection.Open() eventCommand
    = New OleDbCommand("", eventConnection) Dim EvtID As Integer
    Randomize() EvtID = CInt(Int((9000 * Rnd()) + 1)) If updateFlag
    = True Then 'Response.Write(txtDate_time.Text) Call
    EditInfo(eventCommand, "UPDATE Event " & _ "SET EvtDateTime = '"
    & txtDate_time.Text & "'," & _ " Location ='" & txtLocation.Text
    & "'," & _ " EventName ='" & txtEvent.Text & "' " & _
    " WHERE Event.EventID =" & Request.QueryString("eid"))
    Call EditInfo(eventCommand, "UPDATE EventType " & _ "SET EventCategory
    ='" & selCategory.SelectedItem.Text & "', " & _ " Description='"
    & txtDescription.Text & "'" & _ " WHERE EventType.EventID
    =" & Request.QueryString("eid")) Response.Redirect("update.aspx")
    Else Call EditInfo(eventCommand, "INSERT INTO Event (EventID,EvtDateTime,
    Location,EventName) VALUES (" & EvtID & ",'" & txtDate_time.Text & "','"
    & txtLocation.Text & "','" & txtEvent.Text & "')") Call EditInfo(eventCommand,
    "INSERT INTO EventType(EventCategory, Description,EventID) VALUES ('" & selCategory.SelectedItem.Text
    & "','" & txtDescription.Text & "'," & EvtID & ")") End If
    eventConnection.Close() End Sub

    Reply to this Message


  2. #2
    ronnie Guest

    Re: View State


    "phillip" <kannis1@earthlink.net> wrote:
    >
    >Here's my problem. I have a form that updates a database. This happens when
    >you click a link that says update. When you click this link, the current
    >data is displayed in this form. I want to be able to make adjustments to
    >data that's displayed in the form and then submit the form and update the
    >database. What's occuring is when I submit the form, the displayed data

    is
    >switch back to it's previous state and that is what is sent to the database.
    >Therefore no changes or made. This is what appears to be happening. I've
    >disabled Viewstate at the control level and at the page level and it doesn't
    >change anything. I think that's the way it goes with text boxes anyway when
    >you post a page to itself. Below is a snippet of the code. Anyone have any
    >idea how to bet this?
    >
    >Private Sub btnsave_ServerClick(ByVal sender As System.Object, ByVal e As
    >System.EventArgs) Handles btnsave.ServerClick Dim eventConnection
    >As OleDbConnection Dim eventCommand = New OleDbCommand() Dim
    >strInsert As String eventConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
    >Source=C:\eventlog.mdb") eventConnection.Open() eventCommand
    >= New OleDbCommand("", eventConnection) Dim EvtID As Integer


    > Randomize() EvtID = CInt(Int((9000 * Rnd()) + 1)) If updateFlag
    >= True Then 'Response.Write(txtDate_time.Text) Call
    >EditInfo(eventCommand, "UPDATE Event " & _ "SET EvtDateTime = '"
    >& txtDate_time.Text & "'," & _ " Location ='" & txtLocation.Text
    >& "'," & _ " EventName ='" & txtEvent.Text & "' " & _


    > " WHERE Event.EventID =" & Request.QueryString("eid"))


    >Call EditInfo(eventCommand, "UPDATE EventType " & _ "SET EventCategory
    >='" & selCategory.SelectedItem.Text & "', " & _ " Description='"
    >& txtDescription.Text & "'" & _ " WHERE EventType.EventID
    >=" & Request.QueryString("eid")) Response.Redirect("update.aspx")
    > Else Call EditInfo(eventCommand, "INSERT INTO Event (EventID,EvtDateTime,
    >Location,EventName) VALUES (" & EvtID & ",'" & txtDate_time.Text & "','"
    >& txtLocation.Text & "','" & txtEvent.Text & "')") Call EditInfo(eventCommand,
    >"INSERT INTO EventType(EventCategory, Description,EventID) VALUES ('" &

    selCategory.SelectedItem.Text
    >& "','" & txtDescription.Text & "'," & EvtID & ")") End If


    >eventConnection.Close() End Sub
    >
    >Reply to this Message
    >

    are you checking for if not(ispostback) in page load??? the page load will
    run before the button event handler.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center