Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values from one page to another 1

Status
Not open for further replies.

VBRookie

Programmer
May 29, 2001
331
US
Hi,

I'm trying to code a search page in VB.NET that will accept a bunch of values and then display the findings on a separate results page.

I'm using server.transfer in the search page to navigate to the results page. On the results page in the .aspx I have this code under the page directive:

Code:
<%@ Reference Page="StudentFind.aspx" %>

In the page load event I have this code that I'm just using to test if data is being passed correctly or not:

Code:
Dim searchPage As StudentFind

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Response.write(searchPage.txtFName.Text)

 End Sub

When I run this I get this error:

Code:
 Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30390: 'StudentFind.Protected Dim WithEvents txtFName As System.Web.UI.WebControls.TextBox' is not accessible in this context because it is 'Protected'.

Source Error:

Line 9:   '---------------------------------------------------------------------------------
Line 10:  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 11:   Response.write(searchPage.txtFName.Text)
Line 12: 
Line 13:  End Sub


This is my declaration of the textbox:

Code:
<td><asp:TextBox CssClass="style_1" ID="txtFName" runat="server" /></td>

Nowhere have I declared the textbox public or protected or anything so how do I correct this?

Many Thanks,
- VB Rookie
 
Use querystrings to pass info from one to an other page

dim tmp as string=ctype(me.findcontrol("txtFName"), textbox).text.trim
response.redirect("results.aspx?data=" & tmp)


In the results.aspx page use: request.querystring("data") to get it.


* This code is NOT tested
 
I was trying to stay away from querystrings since the user could submit quite a bit of data for the search ...

- VB Rookie
 
You could use the Split() method of the string to generate an array...

dim strPattern() as string=ctype(request.querystring("data"),string).split(" ")

Values from strPattern(0) to strPattern(strPattern.length-1)
 
That's an option but a last resort as we don't want a bloated session object ... there's a way to pass values from one page to the next as I've done it in C# but I can't figure out in VB.NET how to declare my controls as public. I guess that they are automatically declared protected by the 2.0 framework somewhere and I don't know where to go to override that.

Any ideas anyone?

- VB Rookie
 
Expand the Web Form Designer Generated Code in the code behind file. You will see something like this:
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

Remove the Protected.

Jim
 
I'm using .NET 2.0 and VS.NET 2005 ... the form designer code section doesn't appear ... is there another way in 2.0 to access that code?

- VB Rookie
 
Not that I know of, they hide a lot of the code in 2.0 and use Partial Classes now. If anyone knows how to get to it, I'd love to know.
 
I think the querystring method would probably be your best option. If I were designing the page the approach I'd probably go for would be to have two pages (for example, StudentSearch.aspx and StudentShow.aspx).

The first page (StudentSearch.aspx) would allow the user to search using any criteria and the results of their search would be shown on the same page. Each search results would have a clickable link that would take them to the second page and pass the id of the student through as a querysting (e.g. StudentShow.aspx?StudentID=1).

That wasy, only a small amount of querystring data is actually passed and it's the first page that doesn all the work of finding the correct student. All the second page ahs to do, is load the data for the relevant id.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
My 2 cents following the lead of many who have posted here over the years. Avoid Session at all cost; like War, use it only as a last resort (keeping in mind the exception makes the rule).
 
I don't understand the adversion to using session variables.. As long as you are not storing large objects (ie datasets) it will cause no problems. And with the cost of memory, most people have more than enough to cope with a few session variables. Also, if they are used, just make sure to destroy them when you know they are not needed any more. Also, they are more secure than using a query string var if any sensitive data were to be passes.
 
I agree...but there's no point using session variables if they are not needed (and the solution is as straight-forward as it is). The above example that I wrote would only be passing the id of the student and, assuming anyone can view the information on the page, it would make more sense to use a querystring rather than a session variable.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm... I completly agree with your approach. It cuts out passing a lot of unnecessary info.

My comment was directed toward Isadore...

I had the same idea as you after thinking about it for a little while.. you just beat me to it.. :) I should have suggested it since I have done search pages the same way for applications. It definately works well.. good suggestion.


Jim
 
Sorry, I mis-read your post then Jim as I thought you were directing your response to me.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The arguement has to do with server resources, not only to store the Session variable(s) but also to re-drill tables to replenish Session when the data is lost -- the general argument has been to try and devise a mechanism that would not require the use of Session; but sure; if it makes sense to capture the data in Session then use it (I use Session to caputre Menu locations, passwords, etc but I do try to avoid it (out of ~400 aspx pages I run at a couple of sites I use Session variables less than a half dozen times)).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top