Assigned value to user control during Page_Load

C

Cindy

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
 
S

Steve Caliendo

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
 
C

Cindy

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
 
J

John Saunders

Cindy said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top