Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2006, 07:47 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem accessing Request.Form with Master Pages

Hello.

If we have a ListBox and a button on a simple ASPX page, after a submit, we can access its value by Request.Form["ListBox"]. This can be done in Page_Load(), or even earlier in InitializeCulture() method.

But when we add Master Pages, and the page with the ListBox and button are now inside a ContentPlaceHolder, acessing Request.Form["ListBox"], after a submit, always returns null.

The parameter is now hidden in:
Request.Form["ctl00$ContentPlaceHolder1$ListBox1"].

Since in InitializeCulture the objects do not exist yet, we cannot do a Request.Form[ListBox.ClientID]. Furthermore, this returns "ctl00_ContentPlaceHolder1_ListBox1" instead of "ctl00$ContentPlaceHolder1$ListBox1" which would not work as well.

Any idea how to access this value without using this unfriendly string?

Thanks
Fred
Reply With Quote
  #2 (permalink)  
Old March 1st, 2006, 01:15 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Why use Request.Form, why not try ListBox.SelectedValue?

Jim

Reply With Quote
  #3 (permalink)  
Old March 1st, 2006, 04:36 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello there.

Well…because I am trying to access the value selected in the ListBox inside "InitializeCulture()" method, that takes place before Pre_Init() and Page_Load(). Within InitializeCulture (the method that we can override to set our language preferences) no page object is yet created, including the ListBox. Doing “ListBox.SelectedValue” would result in a Null Exception.

I know that accessing the awful string works, but I don't think it is a friendly solution (in terms of programming)...and I am also not sure that the string is always this one.

What bugs me is that this works perfectly if I do not use Master Pages (which I cannot avoid because it offers interesting advantages).

Thanks.
Fred


Reply With Quote
  #4 (permalink)  
Old May 30th, 2006, 03:59 PM
Registered User
 
Join Date: May 2006
Location: Capital Federal, Buenos Aires, Argentina.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sebapiu
Default

try using UniqueID :D

anyways im facing a similar problem i beleive, i've got a BasePage that inherits System.Web.UI.Page, a Default.aspx page that inherits BasePage and a MasterPage (that is being used by default.aspx). This masterpage contains a dropdown with a languages list. I want to access that dropdown from my basepage to get its uniqueId. No problem with that, i use this.Master.FindControl() and i can grab it, althought child page doesnt seem to render after this :(
any ideas ?


Reply With Quote
  #5 (permalink)  
Old January 18th, 2008, 02:52 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi..thnks for the info.
i got my problem solved with this soln

Komila Sachdeva
Software Developer
Reliance engineering Associates (P) Ltd.
Reply With Quote
  #6 (permalink)  
Old January 19th, 2008, 08:03 AM
Registered User
 
Join Date: May 2007
Location: , , India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nice Method [this.master.FindControl()..]..
Thanks..

Vineet Kharbanda
Reply With Quote
  #7 (permalink)  
Old February 14th, 2008, 10:25 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To use the Request.Form in page inside in content you just need to do as follows
Request.Params("ctl00$Content$UpdGroup")

ctl00$Content$UpdGroup is UniqueID of that control,unique id can be found out at rendered page in viewsource or
 Dim content As ContentPlaceHolder = Me.Master.FindControl("content")
 Dim b As Button = content.FindControl("UpdGroup")
 Response.Write(b.UniqueID)


Reply With Quote
  #8 (permalink)  
Old February 14th, 2008, 04:25 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

By the sounds of this, you are using the ListBox for site language selection. Might it make more sense to handle a postback event of the listbox, save the language selection to a session variable, cookie or other persistent datastore and then read that instead of trying to access the listbox? Plus, relying on the listbox to be present may complicate other pages you need to create that might not use the same master page.

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem accessing Request.Form with Master Pages kittu_asa ASP.NET 2.0 Basics 1 February 28th, 2008 09:38 AM
Master Pages, Content Pages and CSS carliviris Visual Studio 2005 0 January 8th, 2008 05:56 PM
Master pages wunnavabk ASP.NET 2.0 Professional 1 June 25th, 2007 07:09 AM
Problem in nested master pages. harsh.kintu ASP.NET 2.0 Professional 2 January 9th, 2007 10:04 AM
Problem with request.form. shankar_v1983 ASP.NET 2.0 Basics 1 January 28th, 2006 10:15 AM



All times are GMT -4. The time now is 11:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.