![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi all, After more than a year programming with ASP.NET 2.0 and VB I am still finding it difficult to leave some habits from classic ASP behind. this is particularly true with cross-page posting. My site uses Master pages and user controls. On an Advanced Search page I have numerous entry boxes and listboxes (keywords, categories, etc.) which are primarily standard HTML. I post this page to a different page which lists results and additional info using a repeater control. I have added a new search criterion in the form of a DropDownList control, specifically for the ease of programming on the server-side -- or so I thought. To retrieve the SelectedValue I find it necessary to use nested FindControl methods to get to the control. An example follows: varOwner = "" 'populate the variable in case the following code fails Dim pp_lstOwner As DropDownList Dim pp_placeholder As ContentPlaceHolder Dim pp_SearchEdit As UserControl pp_placeholder = CType(Page.PreviousPage.Master.FindControl("Conten t1"), ContentPlaceHolder) If Not pp_placeholder Is Nothing Then pp_SearchEdit = CType(pp_placeholder.FindControl("SearchEdit1"), UserControl) If Not pp_SearchEdit Is Nothing Then pp_lstOwner = CType(pp_SearchEdit.FindControl("lstOwner"), DropDownList) If Not pp_lstOwner Is Nothing Then varOwner = pp_lstOwner.SelectedValue End If End If End If Not the most elegant code but it seems to work. All the native HTML controls I use can be accessed simply. varKeyWord1 = Request("txtKeyWord1") Which is much cleaner more easily understood code. I have not utilized ViewState at all in my code to retrieve values. In fact I see many examples (in books) of code "turning off" ViewState to reduce the size of the transmitted pages. I have been reticent to "turn off" any ViewState being concerned about possible adverse consequences... the code works so why break it? My question is can I use ViewState of the DropDownList to retrieve the SelectedValue more easily than the nested mess above? And I still need to learn when I can safely turn off ViewState for Server controls without breaking functionality. BTW...the DropDown list is populated by over 3000 values. Thanks for any suggestions. |
#3
| |||
| |||
|
|
After more than a year programming with ASP.NET 2.0 and VB I am still finding it difficult to leave some habits from classic ASP behind. this is particularly true with cross-page posting. My site uses Master pages and user controls. On an Advanced Search page I have numerous entry boxes and listboxes (keywords, categories, etc.) which are primarily standard HTML. I post this page to a different page which lists results and additional info using a repeater control. |
#4
| |||
| |||
|
|
After more than a year programming with ASP.NET 2.0 and VB I am still finding it difficult to leave some habits from classic ASP behind. this is particularly true with cross-page posting. My site uses Master pages and user controls. On an Advanced Search page I have numerous entry boxes and listboxes (keywords, categories, etc.) which are primarily standard HTML. I post this page to a different page which lists results and additional info using a repeater control. "Cross-page posting" is frowned-upon and you'll find lots of "simple" things that "don't work" when you go down that path. May I suggest that you forget cross-page posting and just have your search page generate the results, store them in the user's session, then redirect to the "results" page. The results page will obtain the results from the session and display them. I think you'll find that working within the "standard" page-lifecycle avoids many of the problems you are encountering. |
#5
| |||
| |||
|
|
Is there any mechanism other than Session variables that I might use to transfer the data in conjunction with a Response.Redirect? |
|
Actually is Response.Redirect the accepted and standard way to move from page to page after using standard postback? I would think that method would be clearly stated in almost all Beginning ASP.NET books or tutorials. Most examples show how server controls are used in a simple postback and don't even bother to cover the topic of moving "state" data (or any other data) between pages. |
#6
| |||
| |||
|
|
Is there any mechanism other than Session variables that I might use to transfer the data in conjunction with a Response.Redirect? Well, there is the Application cache and static variables, but if you use those you'll need to implement some mechanism for keeping each user's data separate as well as "cleaning up" after yourself. If you're using a cross-page postback (meaning the search form actually posts to the results form instead of using a Response.Redirect in the code-behind of the search form) then you can use POST data - see below. Actually is Response.Redirect the accepted and standard way to move from page to page after using standard postback? I would think that method would be clearly stated in almost all Beginning ASP.NET books or tutorials. Most examples show how server controls are used in a simple postback and don't even bother to cover the topic of moving "state" data (or any other data) between pages. Response.Redirect, as far as I know, is the accepted standard. The reason you don't see anything about moving "state" between pages is that it's not standard and it's not "easy". When working with cross-page postbacks you pretty much get the POST data and nothing else. And you have to use Request.Form or Request.Params to get at those, I believe. If the viewstate *is* posted to the new page (it is just a hidden form field, after all) I think you'll have to decode it and parse it yourself. I've never gone down that path, so I'm probably not the best guy to be giving advice here. Just trying to give you some things to look into. Try setting a breakpoint in the destination page and checking "Request.Params" to see what you're given. Maybe you'll find enough in there to solve your problem. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |