By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,811 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,811 IT Pros & Developers. It's quick & easy.

Assigned value to user control during Page_Load

P: n/a
ASP.NET - C# (User Control)

I have a drop-down as usercontrol.

In the user control's Page_Init , the drop down gets
populated.

The SelectedItem.Text is retrived using property get
The Value of the drop-down is assigned using property set.

This user control is placed on an aspx page on which I am
trying
to assign the control a value.

I tried this in the Page_Load event of the aspx page - it
gives me this eror:-
Object reference not set to an instance of an object

It gives the same error in Page_PreRender event.

It works fine when tried in a button event.

The same logic works fine in VB but not in CSharp.

Any help will be appreciated.

Thanks


Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You need to populate the dropdownlist in the Page_Load - not the control's
init. You can set / get the selected item from the ddl only after you have
populated it.

Steve

"Cindy" <an*******@discussions.microsoft.com> wrote in message
news:20*****************************@phx.gbl...
ASP.NET - C# (User Control)

I have a drop-down as usercontrol.

In the user control's Page_Init , the drop down gets
populated.

The SelectedItem.Text is retrived using property get
The Value of the drop-down is assigned using property set.

This user control is placed on an aspx page on which I am
trying
to assign the control a value.

I tried this in the Page_Load event of the aspx page - it
gives me this eror:-
Object reference not set to an instance of an object

It gives the same error in Page_PreRender event.

It works fine when tried in a button event.

The same logic works fine in VB but not in CSharp.

Any help will be appreciated.

Thanks

Nov 18 '05 #2

P: n/a
Steve,
Even if I populate it in the Page_load event, it gives the
same error.
How come it works with vb & not with c#.

Cindy
-----Original Message-----
You need to populate the dropdownlist in the Page_Load - not the control'sinit. You can set / get the selected item from the ddl only after you havepopulated it.

Steve

"Cindy" <an*******@discussions.microsoft.com> wrote in messagenews:20*****************************@phx.gbl...
ASP.NET - C# (User Control)

I have a drop-down as usercontrol.

In the user control's Page_Init , the drop down gets
populated.

The SelectedItem.Text is retrived using property get
The Value of the drop-down is assigned using property set.
This user control is placed on an aspx page on which I am trying
to assign the control a value.

I tried this in the Page_Load event of the aspx page - it gives me this eror:-
Object reference not set to an instance of an object

It gives the same error in Page_PreRender event.

It works fine when tried in a button event.

The same logic works fine in VB but not in CSharp.

Any help will be appreciated.

Thanks

.

Nov 18 '05 #3

P: n/a
"Cindy" <an*******@discussions.microsoft.com> wrote in message
news:21*****************************@phx.gbl...
Steve,
Even if I populate it in the Page_load event, it gives the
same error.
How come it works with vb & not with c#.


Turn Options Strict On in VB and you'll probably find that VB.NET was doing
something for you behind your back.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.