Postback, session state ETC

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hi

I've almost finished the web page I'm developing (with a great deal of help
from this group - thanks everyone).

My page contains 3 drop down boxes, a SEARCH button, a datagrid (populated
using a stored procedure, the stored procedure uses the selectitem in the
drop down boxes for the parameters), and a SUBMIT button.

I'm not sure how to bring it all together, when the page starts I only want
the drop down boxes and the SEARCH button to be displayed, when SEARCH is
pressed I want thoe drop down boxes to be visible but inactive and the
datagrid to be shown.

I believe when the SEARCH button is pressed a postback occurs and the page
is reloaded, how can I get my page to know which "STATE" it's in, do I use
session cookies or something along those lines?

Thanks
 
Hi Paul,

There are a number of ways to track a user's session variables through
postbacks and modify the 'visible' attributes of the controls you want to
show accordingly.

If you don't want to use the Session object, you can put a Literal object on
a form and set it's visible attribute to False, and store some text or an
integer in the WhateverLiteral.Text property, and it will get posted back
and "remember" it's value.

You can use the standard session object (syntax: Session("variablename") =
value), of course...

And one snippet of code that you will find yourself writing often with
ASP.NET is:

If Not Page.IsPostBack Then
' actions to take if page is not a postback (i.e., user loads page for
the first time)
End If

For your particular example, you may want to do something like the following
(providing there are only 2 states of your page)

If Not Page.IsPostBack Then
DropDownBox1.Enabled = True
DropDownBox2.Enabled = True
DropDownBox3.Enabled = True

SearchButton.Enabled = True

DataGrid.Visible = False
Else
DropDownBox1.Enabled = False
DropDownBox2.Enabled = False
DropDownBox3.Enabled = False

SearchButton.Enabled = False
DataGrid.Visible = True
End If

Let me know if this helps!

Brandon
 
I have the session variables working to some degree, but I have this code on
my go button event:

Private Sub GOButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles GOButton.Click
Session("PHYSOFFICE") = PhysOffice.SelectedValue
Session("MATCH") = MatchCriteria.SelectedValue
Session("VIEWMODE") = ViewMode.SelectedValue
End Sub

And then on my Page_Load section I set my sproc parameters like this :-

GetEmpsSelect.Parameters("@officename").Value = Session("PHYSOFFICE")
GetEmpsSelect.Parameters("@match_criteria").Value = Session("MATCH")
GetEmpsSelect.Parameters("@view_mode").Value = Session("VIEWMODE")

The session variables are blank, therefore my sproc breaks.

Any ideas?
 
Back
Top