Passing Public Variables between Web Forms

wings9697

Member
Joined
Aug 27, 2007
Messages
23
Location
Washington, DC
Programming Experience
10+
Hi. I'm currently in the process of building a Case Log for our Crime Scene Investigation Team. It consists of set of web forms, one for each type of evidence and one main page as the mainmenu/application driver. Basically, an agent logs in with his ID code and a gets a list of all current cases they're working on plus the option to create a new case.

The problem I'm having is that after I pull the agent's current case list from the main SQL table, I wanted to put the agent's ID number and the case number value (if they were working on an existing case) into a Public variable which I could use to pull the case reports from each unit's (Medical Examiner, Garage, Property, etc.) table as requested. But after putting the values into two public variables, when I use Response.Redirect(pagename.aspx) to go to the requested form, the variables data didn't follow to the next form.

I then built a class to hold the variables, that didn't work. It will only let me create a new copy of the class for that form.
I tried the XML PreviousPageType tag, but all that got me was a NULL exception.
I even looked at some of the examples given in the forum, but they were only good if you were using modal forms, which unfortuantly, I'm not...

Can anyone give me any idea of what I'm missing? This has really stumped me...thanks in advance for any help you can provide.....
 
giadich - I saw some code that pertained to that option :

VB.NET:
<script language=JavaScript runat=server> 

function Session_OnStart ( ) 
{ 
   // you must lock the global Application object 
   // when writing to it - ok to read without lock 
   Application.Lock ( ); 

   // one more active user 
   Application ( 'ActiveUsers' )++; 

   Application.Unlock ( ); 
} 

</script>

but my only question was where to create the file at, and how do I change the value, it seemed this was designed to store constants....

I then tried to put them in the web.config, but when I tried to access them in my code files with the statement I was told to use ->

Dim GlobalCase As String = System.Configuration!System.Configuration.ConfigurationSettings.AppSettings("GlobalCase") = usrCaseNum

my .aspx file got hosed, it called every XML code line an error....


JohnH - that page is where I got the idea for the PreviousPageType tag. The problem is when I added the code to attempt retrieval of the value from the previous page :

VB.NET:
  Dim prevCH As TextBox
        prevCH = CType(FormView1.FindControl("case_agentnumTextBox"), TextBox)

        If Not Page.PreviousPage Is Nothing Then
            Dim SourceTextBox As TextBox
            SourceTextBox = CType(PreviousPage.FindControl("TextBox1"), _
                TextBox)
            If Not SourceTextBox Is Nothing Then
                prevCH.Text = SourceTextBox.Text
            End If
        End If

SourceTextBox.Text which is supposed to hold the agent ID Number from the menu page is blank.

Now in a box at the bottom of the page it says :

The FindControl method finds controls in the current naming container. If the control you are looking for is inside another control (typically, inside a template), you must first get a reference to the container, and then search the container to find the control that you want to get.

I am using templates, so when they mention "reference to the container", do they mean the form name? If so, how do you actually code that reference?
 
Application.Lock ( );

// one more active user
Application ( 'ActiveUsers' )++;

Application.Unlock ( );

that's application variable not session variable. try something like this in your page.

VB.NET:
session ("blah") = "blah blah"
response.write(session("blah"))

i think the error you are getting the error because the variable has not been initialized before you try to increment it.

also, with regards to previouspagetype, it's only pertaining to 2.0 or higher which i see you noted in your profile - just thought i point that out ;)
 
giadich,

VB.NET:
session ("blah") = "blah blah"
response.write(session("blah"))

thanks, this worked like a champ... I created my two session variables right after my SQL statement found the right row and was able to cast the ID and Case values into their fields on the proceding web pages...

only drawback is it printed the variables in the upper left corner of the page that created them, but I can live with that...

Thanks for all of you guys' help...
 
Back
Top