473,545 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get DropDownList.Se lectedValue from Page_PreInit Event

Is it possible to get DropDownList.Se lectedValue in Page_PreInit() event
during the postback?
Jan 12 '08 #1
18 5410
Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:
Is it possible to get DropDownList.Se lectedValue in Page_PreInit() event
during the postback?
Jan 12 '08 #2
Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:
Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:
Is it possible to get DropDownList.Se lectedValue in Page_PreInit() event
during the postback?

Jan 14 '08 #3
Yes, that would be easier. Sorry, I typically never use Request.Form and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as the
control tree has not yet been built, it would be difficult for the Page to
calculate the UniqueID, and typically the Control instance would be null as
well no?

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:
Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:
Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:
Is it possible to get DropDownList.Se lectedValue in Page_PreInit() event
during the postback?
>
>
>
Jan 14 '08 #4
Hi Chad,

The control tree is already created in PreInit event, as the aspx page
compiler puts all the declarations into FrameworkInitia lize() method which is
called from Page.ProcessReq uest (member of the IHttpHandler interface) (have
a look at the content of your website's asp.net folder, especially at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:
Yes, that would be easier. Sorry, I typically never use Request.Form and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as the
control tree has not yet been built, it would be difficult for the Page to
calculate the UniqueID, and typically the Control instance would be null as
well no?

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:
Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:
Unfortunately I believe the answer is no. Is there a reason you need this
value before the page is initialized?
>
You could potentially inject the value into a cookie using JavaScript using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value upon
post-back. I believe the HttpRequest stack has been created by then and upon
calling the OnPreInit method of your page, has built these values from the
request headers.
>
--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
>
>
"Redhairs" wrote:
>
Is it possible to get DropDownList.Se lectedValue in Page_PreInit() event
during the postback?

Jan 15 '08 #5
It doesn't work and return error msg "Object reference not set to an
instance of an object"
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:EF******** *************** ***********@mic rosoft.com...
Hi Chad,

The control tree is already created in PreInit event, as the aspx page
compiler puts all the declarations into FrameworkInitia lize() method which
is
called from Page.ProcessReq uest (member of the IHttpHandler interface)
(have
a look at the content of your website's asp.net folder, especially at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:
>Yes, that would be easier. Sorry, I typically never use Request.Form and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as the
control tree has not yet been built, it would be difficult for the Page
to
calculate the UniqueID, and typically the Control instance would be null
as
well no?

--
Chad Scharf
______________ _______________ __
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:
Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you need
this
value before the page is initialized?

You could potentially inject the value into a cookie using JavaScript
using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value
upon
post-back. I believe the HttpRequest stack has been created by then
and upon
calling the OnPreInit method of your page, has built these values
from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.Se lectedValue in Page_PreInit()
event
during the postback?


Jan 16 '08 #6
Hi Redhairs,

I checked it and it works fine. Are you by any chance create this control
dynamically or drop down list is placed inside a tamplated control? Could you
please pase some code?

Regards
--
Milosz
"Redhairs" wrote:
It doesn't work and return error msg "Object reference not set to an
instance of an object"
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:EF******** *************** ***********@mic rosoft.com...
Hi Chad,

The control tree is already created in PreInit event, as the aspx page
compiler puts all the declarations into FrameworkInitia lize() method which
is
called from Page.ProcessReq uest (member of the IHttpHandler interface)
(have
a look at the content of your website's asp.net folder, especially at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:
Yes, that would be easier. Sorry, I typically never use Request.Form and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as the
control tree has not yet been built, it would be difficult for the Page
to
calculate the UniqueID, and typically the Control instance would be null
as
well no?

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:

Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you need
this
value before the page is initialized?
>
You could potentially inject the value into a cookie using JavaScript
using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your value
upon
post-back. I believe the HttpRequest stack has been created by then
and upon
calling the OnPreInit method of your page, has built these values
from the
request headers.
>
--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
>
>
"Redhairs" wrote:
>
Is it possible to get DropDownList.Se lectedValue in Page_PreInit()
event
during the postback?



Jan 16 '08 #7
Yes, I use use the master page so the DropDownList was placed in the Content
control,
how to solve this problem?
Btw, waht's the difference between ClientID and UniqueID?
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:BC******** *************** ***********@mic rosoft.com...
Hi Redhairs,

I checked it and it works fine. Are you by any chance create this control
dynamically or drop down list is placed inside a tamplated control? Could
you
please pase some code?

Regards
--
Milosz
"Redhairs" wrote:
>It doesn't work and return error msg "Object reference not set to an
instance of an object"
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:EF******* *************** ************@mi crosoft.com...
Hi Chad,

The control tree is already created in PreInit event, as the aspx page
compiler puts all the declarations into FrameworkInitia lize() method
which
is
called from Page.ProcessReq uest (member of the IHttpHandler interface)
(have
a look at the content of your website's asp.net folder, especially at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:

Yes, that would be easier. Sorry, I typically never use Request.Form
and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as
the
control tree has not yet been built, it would be difficult for the
Page
to
calculate the UniqueID, and typically the Control instance would be
null
as
well no?

--
Chad Scharf
______________ _______________ __
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:

Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you
need
this
value before the page is initialized?

You could potentially inject the value into a cookie using
JavaScript
using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your
value
upon
post-back. I believe the HttpRequest stack has been created by
then
and upon
calling the OnPreInit method of your page, has built these values
from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.Se lectedValue in
Page_PreInit()
event
during the postback?




Jan 17 '08 #8
Howdy,

In this case (masterpage) you have to manually find the control as it has
not been referenced yet (but it has been instantiated in the contrnt place
holder):

string selectedValue =
Request.Form[Master.FindCont rol("placeholde rname").FindCon trol("ddlID").U niqueID];

It's quite nasty, so my question is why would you need that? The difference
bewteen UniqueID and ClientID is the first is used as "name" attribute for
input controls and it consists of ID + parents ID (simpifying) separated by a
dollar character, whilst ClientID is used as "id" attribute of all the html
elements that are generated by web controls/html controls with runat=server
separated by underscore char. For more info check this out:
http://www.shanebauer.com/Weblog/Per...d4da9b533.aspx
--
Milosz
"Redhairs" wrote:
Yes, I use use the master page so the DropDownList was placed in the Content
control,
how to solve this problem?
Btw, waht's the difference between ClientID and UniqueID?
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:BC******** *************** ***********@mic rosoft.com...
Hi Redhairs,

I checked it and it works fine. Are you by any chance create this control
dynamically or drop down list is placed inside a tamplated control? Could
you
please pase some code?

Regards
--
Milosz
"Redhairs" wrote:
It doesn't work and return error msg "Object reference not set to an
instance of an object"
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:EF******** *************** ***********@mic rosoft.com...
Hi Chad,

The control tree is already created in PreInit event, as the aspx page
compiler puts all the declarations into FrameworkInitia lize() method
which
is
called from Page.ProcessReq uest (member of the IHttpHandler interface)
(have
a look at the content of your website's asp.net folder, especially at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:

Yes, that would be easier. Sorry, I typically never use Request.Form
and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing as
the
control tree has not yet been built, it would be difficult for the
Page
to
calculate the UniqueID, and typically the Control instance would be
null
as
well no?

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:

Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you
need
this
value before the page is initialized?
>
You could potentially inject the value into a cookie using
JavaScript
using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your
value
upon
post-back. I believe the HttpRequest stack has been created by
then
and upon
calling the OnPreInit method of your page, has built these values
from the
request headers.
>
--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
>
>
"Redhairs" wrote:
>
Is it possible to get DropDownList.Se lectedValue in
Page_PreInit()
event
during the postback?





Jan 17 '08 #9
Thanks for your quick response.

I can find the
Master.FindCont rol("placeholde rname").FindCon trol("ddlID").U niqueID in
Page_PreInit()
but still get "Object reference not set to an instance of an object" if try
to access
Request.Form[Master.FindCont rol("placeholde rname").FindCon trol("ddlID").U niqueID];

But the ddlID.UnigueID is one of the keys of Request.Form collection.
Can't figure out why.


"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:9C******** *************** ***********@mic rosoft.com...
Howdy,

In this case (masterpage) you have to manually find the control as it has
not been referenced yet (but it has been instantiated in the contrnt place
holder):

string selectedValue =
Request.Form[Master.FindCont rol("placeholde rname").FindCon trol("ddlID").U niqueID];

It's quite nasty, so my question is why would you need that? The
difference
bewteen UniqueID and ClientID is the first is used as "name" attribute for
input controls and it consists of ID + parents ID (simpifying) separated
by a
dollar character, whilst ClientID is used as "id" attribute of all the
html
elements that are generated by web controls/html controls with
runat=server
separated by underscore char. For more info check this out:
http://www.shanebauer.com/Weblog/Per...d4da9b533.aspx
--
Milosz
"Redhairs" wrote:
>Yes, I use use the master page so the DropDownList was placed in the
Content
control,
how to solve this problem?
Btw, waht's the difference between ClientID and UniqueID?
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:BC******* *************** ************@mi crosoft.com...
Hi Redhairs,

I checked it and it works fine. Are you by any chance create this
control
dynamically or drop down list is placed inside a tamplated control?
Could
you
please pase some code?

Regards
--
Milosz
"Redhairs" wrote:

It doesn't work and return error msg "Object reference not set to an
instance of an object"
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.plwrot e in message
news:EF******* *************** ************@mi crosoft.com...
Hi Chad,

The control tree is already created in PreInit event, as the aspx
page
compiler puts all the declarations into FrameworkInitia lize() method
which
is
called from Page.ProcessReq uest (member of the IHttpHandler
interface)
(have
a look at the content of your website's asp.net folder, especially
at
compiled pages). Therefore, it's safe to run the code:
Request.Form[ddl.uniqueID]

Regards
--
Milosz
"Chad Scharf" wrote:

Yes, that would be easier. Sorry, I typically never use
Request.Form
and
forgot about it.

Is the UniqueID available though in the Page_PreInit event, seeing
as
the
control tree has not yet been built, it would be difficult for the
Page
to
calculate the UniqueID, and typically the Control instance would be
null
as
well no?

--
Chad Scharf
______________ _______________ __
http://www.chadscharf.com
"Milosz Skalecki [MCAD]" wrote:

Howdy,

Why using cookie, wouldn't be easier just by using
string selectedValue = Request.Form[yourDropDown.Un iqueID]
?
--
Milosz
"Chad Scharf" wrote:

Unfortunately I believe the answer is no. Is there a reason you
need
this
value before the page is initialized?

You could potentially inject the value into a cookie using
JavaScript
using
the OnSubmit event of your form, then read that using the
HttpContext.Cur rent.Request.Co okies collection to retrieve your
value
upon
post-back. I believe the HttpRequest stack has been created by
then
and upon
calling the OnPreInit method of your page, has built these
values
from the
request headers.

--
Chad Scharf
_______________ _______________ _
http://www.chadscharf.com
"Redhairs" wrote:

Is it possible to get DropDownList.Se lectedValue in
Page_PreInit()
event
during the postback?




Jan 17 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5461
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last...
3
2690
by: sling blade | last post by:
Hi, I have a dropdownlist in my DataList control and I am trying to set the SelectedItem property of the dropdownlist so when the datalist displays the user will see the text in the dropdownlist set to a predetermined value. I can set the SelectedItem property easy enough and get the dropdownlist to work fine just so long as the...
3
2485
by: Carlos Lozano | last post by:
Hello, I am having a problem getting the selectedValue from a dropdownlist that is populated with a dataReader and just can't see the problem. I did the following: dim dr as DataReader dr = DataReader(sSQLcmd) Me.DropDownList1.DataSource = dr
9
3405
by: Lammert | last post by:
Good morning, I create an ASP.NET 2.0 web application. The situation: 1. One masterpage where the users can select an organisation in a DropDownList. 2. Different content pages. I will get the value of the DropDownList in the Page_PreInit event. How can I do that? The content in the content and master pages is based on
1
5394
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow> <asp:TableCell CssClass="asp-table-header">Select Route<asp:Label ID="lblTest" runat="server"></asp:Label> </asp:TableCell>
3
9833
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
Hi, Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the controls are inside a user control and this user control inside a parent user control with an update panel. Can you guys help me hwo to retain the values. I have set EnableViewState to true. Where is...
2
1691
by: Francois | last post by:
Hello, ASP NET 2.0 visual studio 2005. I am tryng to create a dynamic dropdownlist in the Page_Load event. myDDL = new DropDownList I populate it in the IsPostBack branch of Page_Load.
15
1369
by: Chris | last post by:
Hi, When choosing a value in the dropdownlist, i try to put that selectedvalue in the label, but i always get the first value 'a'. EnableViewState is by default set to true, so ... what's wrong in my code? Thanks Chris Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
1
4913
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over time. The problem is that when an item has been removed from the lookup table, and a user wants to retrieve a record that used the deleted item,...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.