Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > selectedindex after dropdownlist is added to placeholder

Reply
Thread Tools

selectedindex after dropdownlist is added to placeholder

 
 
Michael Tanner
Guest
Posts: n/a
 
      01-20-2004
I have created a custom control that derives from the PlaceHolder control.
Based on a property setting, I load a DropDownList or a TextBox into the
PlaceHolder control. I load the DropDownList or TextBox control in
protected override void OnPreRender(EventArgs e).

The issue that I have is getting the SelectedIndex from the DropDownList
after a postback. The PlaceHolder control does not have the SelectedIndex
property and I can't figure out how to maintain the DropDownList after a
postback - so FindControl doesn't work for me.

Any ideas would be appreciated.


 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      01-22-2004
Hi Michael,

Note that adding the child controls at PreRender may be too late, as several
key event (Init, Load, viewstate loading,e tc) had already been fired and
your added control wasn't there at the proper time. If you're writing a
composite custom control then CreateChildControls is the place where to
create child controls.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

"Michael Tanner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have created a custom control that derives from the PlaceHolder control.
> Based on a property setting, I load a DropDownList or a TextBox into the
> PlaceHolder control. I load the DropDownList or TextBox control in
> protected override void OnPreRender(EventArgs e).
>
> The issue that I have is getting the SelectedIndex from the DropDownList
> after a postback. The PlaceHolder control does not have the SelectedIndex
> property and I can't figure out how to maintain the DropDownList after a
> postback - so FindControl doesn't work for me.
>
> Any ideas would be appreciated.
>
>



 
Reply With Quote
 
 
 
 
Nathanael Schulte
Guest
Posts: n/a
 
      01-23-2004
I'm having a similar problem on PostBack for a DropDownList.

I have a page called ManualAdd2.aspx
That page contains instances of two user controls:
HeaderBlock.ascx and ctlBrowse.ascx

HeaderBlock.ascx also contains an instance of ctlBrowse.ascx

ctlBrowse contains a DropDownList and a TextBox.

When I run ManualAdd2.aspx, the instance of ctlBrowse that is contained
within the HeaderBlock control holds state for the DropDownlist in it's
copy of ctlBrowse just fine.

The instances of ctlBrowse that just reside in ManualAdd2.aspx DO NOT
hold their state, however.

I've looked at the declarations of the control instances and cannot find
a single difference in declaration.

Any ideas?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Michael Tanner
Guest
Posts: n/a
 
      01-28-2004
Victor,

Thanks for you reply. I found CreateChildControl just a few hours after I
posted.

Thanks again,
Michael

"Victor Garcia Aprea [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Michael,
>
> Note that adding the child controls at PreRender may be too late, as

several
> key event (Init, Load, viewstate loading,e tc) had already been fired and
> your added control wasn't there at the proper time. If you're writing a
> composite custom control then CreateChildControls is the place where to
> create child controls.
>
> --
> Victor Garcia Aprea
> Microsoft MVP | ASP.NET
> Looking for insights on ASP.NET? Read my blog:
> http://obies.com/vga/blog.aspx
> To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
>
> "Michael Tanner" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I have created a custom control that derives from the PlaceHolder

control.
> > Based on a property setting, I load a DropDownList or a TextBox into the
> > PlaceHolder control. I load the DropDownList or TextBox control in
> > protected override void OnPreRender(EventArgs e).
> >
> > The issue that I have is getting the SelectedIndex from the DropDownList
> > after a postback. The PlaceHolder control does not have the

SelectedIndex
> > property and I can't figure out how to maintain the DropDownList after a
> > postback - so FindControl doesn't work for me.
> >
> > Any ideas would be appreciated.
> >
> >

>
>



 
Reply With Quote
 
Nathanael Schulte
Guest
Posts: n/a
 
      01-28-2004
Hey,

I had a similar issue to yours and maybe your problem is not the same,
but I'll share what fixed it for me anyway:

What I was finding was that on postback, my DropDownList would always to
back to the first entry, no matter what I picked. I pulled up the page
in the browser then went to View Source in IE. What I noticed was that
the Value for the rendered <OPTION> control was the same for every
entry. In other words, then I populated the DropDownList from a
database, the SelectedItem.Value was the same for every entry in the
drop down list, so it would always go back to the first entry in the
list and the SelectedIndexChanged event would never fire.
So, I would recommend making sure there is a unique value for every
entry in the DropDownList.

Hope this helps.

Thanks,
thanie2001

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When I set the DropDownList.SelectedIndex of ONE DropDownList they ALL change! S_K ASP .Net 5 11-14-2007 04:51 PM
DropDownList inside GridView: How to set SelectedIndex for the DropDownList? keithb ASP .Net 1 11-01-2006 05:24 AM
DropDownList.SelectedIndex doesn't work after Databind =?Utf-8?B?SmFzb24gQ2hhbg==?= ASP .Net 1 11-22-2005 08:07 AM
Build control in a placeholder or like a placeholder nail ASP .Net Building Controls 0 09-10-2004 07:57 PM
DropDownList SelectedIndex stuck at -1 after IsPostBack Matthew ASP .Net 1 11-12-2003 08:12 PM



Advertisments