p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Problem accessing Request.Form with Master Pages (http://p2p.wrox.com/showthread.php?t=39176)

niceFEPF February 28th, 2006 07:47 PM

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

jbenson001 March 1st, 2006 01:15 AM

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

Jim


niceFEPF March 1st, 2006 04:36 AM

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



sebapiu May 30th, 2006 03:59 PM

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 ?



Komila January 18th, 2008 02:52 AM

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

Komila Sachdeva
Software Developer
Reliance engineering Associates (P) Ltd.

vineet_online1 January 19th, 2008 08:03 AM

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

Vineet Kharbanda

Suresh Punna February 14th, 2008 10:25 AM

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)



planoie February 14th, 2008 04:25 PM

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


All times are GMT -4. The time now is 02:31 PM.

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