Ask a Question related to ASP.NET Building Controls, Design and Development.
-
DotNetJunky #1
custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it
resides inside a datagrid column and i set the selecteddate property of the
usercontrol from one of the DataBinder.Eval 's ... everythign works fine.
The datepicker also works fine on a regular page, and will normally persist
its viewstate on a page.postback event. However now i am trying to use it in
a datagrid and running into problems.
When the datagrid is re-bound on postback or it's selectedIndexChanged
event, the usercontrol's dropdowns become empty. It isnt saving it's
viewstate and i cant figure out why.
Can someone point me to the right direction of how to persist the state of a
usercontrol's dropdownlists on re-bind of the datagrid? I have tried going
into the usercontrol and removing the if (!Page.IsPostBack) <binding of the
data....> procedure in the OnLoad event, however that solves the empty
dropdowns on postback/re-bind of the datagrid, but the selectedDate property
doesn't get re-set again. So i am still screwed there.
Inside the usercontrol i am viewstating the properties of it, IE, the
selecteddate, selectedday/month/year , etc. Everything is viewstated with a
prefix of this.ID + "_" + propertyvalue.
Thanks in advance,
- DNJ
DotNetJunky Guest
-
can i use dynamic variable inside a dataadapter and bind to datagrid
Hi I want to use a sql designed in the dataadapter and I want to pass a variable so it can retrieve related data by using "WHERE" clause in the... -
UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback
I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of... -
DataGrid empty on Postback with ViewState enabled
Hi there! I'm having a problem with the datagrid control. I can't seem to get the datagrid to restore it's contents from ViewState. A... -
viewstate of the user control inside datagrid...
Hi there! I have datagrid with template column and I am using the same user control for display (in ItemTemplate) and collect (in EditItemTemplate)... -
Problem with UserControl Property in a DataGrid after Postback
Hello, I have this page.aspx ---------- <%@ Register TagPrefix="uc1" TagName="Userdetails" Src="Userdetails.ascx" %> ... <asp:datagrid... -
recoil@community.nospam #2
Re: custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
Your user control should implement INamingContainer which is an
interface that has no methods, therefore implementing it is extremely
easy
MyUserControl: WebControl, INamingContainer
Then make sure that your UserControl is always given the same ID upon
postback and done so in a timely manner.
Follow these 2 steps and your usercontrol should be able to maintain
its viewstate across postbacks
recoil@community.nospam Guest
-
DotNetJunky #3
Re: custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid
Well i was already implementing INamingContainer, can't even remember if it
was purposely or not:
public class SimpleDatePicker : System.Web.UI.UserControl,
System.Web.UI.INamingContainer
However, as far as giving it the same ID on postback - I am not dynamically
adding the control to the datagrid, i am actually creating a tag on the page
for the usercontrol and putting it right into the grid in design-time such
as:
<%@ Register TagPrefix="UserControl" TagName="SimpleDatePicker"
Src="usercontrols/SimpleDatePicker.ascx" %>
<UserControl:SimpleDatePicker id="DatePickerExpires" runat="Server"
SelectedDate='<%#DataBinder.Eval(Container.DataIte m, "DATE_EXPIRES") %>'>
</UserControl:SimpleDatePicker>
So would that make a difference? Do i need to dynamically add it on the
datagrid ItemDataBound event or something?
Thanks for your help, you definitely have me started in the right
direction...
- DNJ
"recoil@community.nospam" <marc.derider@gmail.com> wrote in message
news:1111424498.215454.120270@l41g2000cwc.googlegr oups.com...> Your user control should implement INamingContainer which is an
> interface that has no methods, therefore implementing it is extremely
> easy
> MyUserControl: WebControl, INamingContainer
>
>
> Then make sure that your UserControl is always given the same ID upon
> postback and done so in a timely manner.
>
> Follow these 2 steps and your usercontrol should be able to maintain
> its viewstate across postbacks
>
DotNetJunky Guest



Reply With Quote

