Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Persist Variable on Postback
    primarykey
    data
    text
    <p>I created a single page (with code behind .vb) and created Public intFileID As Integer</p> <p>in the Page load I check for the querystring and assign it if available or set intFileID = 0.</p> <pre><code>Public intFileID As Integer = 0 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then If Not Request.QueryString("fileid") Is Nothing Then intFileID = CInt(Request.QueryString("fileid")) End If If intFileID &gt; 0 Then GetFile(intFileID) End If End If End Sub Private Sub GetFile() 'uses intFileID to retrieve the specific record from database and set's the various textbox.text End Sub </code></pre> <p>There is a click event for the Submit button that inserts or updates a record based on the value of the intFileID variable. I need to be able to persist that value on postback for it all to work.</p> <p>The page simply inserts or updates a record in a SQL database. I'm not using a gridview,formview,detailsview, or any other rad type object which persists the key value by itself and I don't want to use any of them.</p> <p>How can I persist the value set in intFileID without creating something in the HTML which could possibly be changed.</p> <p><strong>[EDIT] Changed Page_Load to use ViewState to persist the intFileID value</strong></p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then If Not Request.QueryString("fileid") Is Nothing Then intFileID = CInt(Request.QueryString("fileid")) End If If intFileID &gt; 0 Then GetFile(intFileID) End If ViewState("intFileID") = intFileID Else intFileID = ViewState("intFileID") End If End Sub </code></pre>
    singulars
    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.
 

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