Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropdownList autopostback

Status
Not open for further replies.

ggeorgiou01

Programmer
Apr 11, 2005
60
GB
Hi,

I have a problem where I have a default.aspx page, with serveral usercontrols in the .aspx page.

I also have a dropdownlist on one of the controls with the attribute autopostback set to true. When i change the selectedindex of this dropdownlist, it always seems to remove the control from the page.

So basically, on change of my dropdownlist (or any other) how do I keep the state of my web-page ? Its starting to get very fustrating!

Many Thanks,
George
 
Thank you for such a swift reply Sirius.

Yes - EnableViewState is set to true for both my user control and my aspx page.
 
Scary... I've never seen a control just get removed from a page.

This control was created in Design time right... not at Run time? Are you sure its Visible property isn't just getting set to False.

Senior Software Developer
 
You said user control and aspx page had view state enabled, but how about the drop down list in the user control?
 
Are you creating any of the controls dynamically, or loading any of the user controls dynamically?
 
Thanks for all the replys guys. I will post some of my code tommorrow morning when I get into work!
 
Morning guys,

So here is my code as promised.

Default.aspx
---------------------------------------------

<asp:ImageButton ID="SupplierBtn" runat="server" OnClick="SupplierBtn_Click" ImageUrl="../Images/Tabs/tab_dim.gif" EnableViewState="true" />

<asp:ImageButton ID="NoteBtn" runat="server" OnClick="NoteBtn_Click" ImageUrl="../Images/Tabs/tab.gif" EnableViewState="true" />

<asp:ImageButton ID="AuthorityBtn" runat="server" OnClick="AuthorityBtn_Click" ImageUrl="../Images/Tabs/tab.gif" EnableViewState="true" />


Default.aspx.cs
---------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DetailsPlaceHolder.Controls.Add(Page.LoadControl("Controls/Supplier.ascx"));
}
}

#region Event commands

protected void SupplierBtn_Click(object sender, EventArgs e)
{
DetailsPlaceHolder.Controls.Add(Page.LoadControl("Controls/Supplier.ascx"));
}

protected void NoteBtn_Click(object sender, EventArgs e)
{
DetailsPlaceHolder.Controls.Add(Page.LoadControl("Controls/Notes.ascx"));
}

protected void AuthorityBtn_Click(object sender, EventArgs e)
{
DetailsPlaceHolder.Controls.Add(Page.LoadControl("Controls/Authority.ascx"));
}

#endregion



Supplier.ascx.cs
---------------------------------------------

<asp:DropDownList AutoPostBack="true" ID="SupplierDdl" runat="server" DataValueField="ID" DataTextField="SupplierName" EnableViewState="true">
</asp:DropDownList>


.....so when i change my selected index on my dropdownlist the control dissapears and drisplay nothin (blank) into my placeholder... any idea's guys ?!



 
You have to load all dynamic controls every time the page loads. At the moment, there is only one usercontrol that is being loaded when the page loads.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
So are you suggesting the best way of doing this is to load all controls on page_load, then depending on my button onclick, I make the relevant controls visible/hidden ?!
 
If I had to create dynamic controls, I would define any logic that decided whether they were needed and if they were, create them. This would all be done in the Page Init event.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top