J
John Kotuby
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("Content1"),
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.
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("Content1"),
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.