In-Reply-To: <rucPjY#
[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <#sEg#
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
NNTP-Posting-Host: dsl092-132-209.chi1.dsl.speakeasy.net 66.92.132.209
Lines: 1
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet.buildingcontrols:8778
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
Hello again Jeffrey, nice to speak with you again. I appreciate your
efforts.
Let me describe in more detail the issue I am facing.
rbl1 is a design time only control that has three ListItems, call them
rbl1.1, rbl1.2 and rbl1.3. Since this control is design-time only, I
have no problems with ViewState for rbl1 at all.
rbl2 is also a design time control, BUT, it also has dynamic/run-time
'issues'. Let me try to explain.
By default, rbl2 has 3 ListItems, let's call them rbl2.1, rbl2.2 and
rbl2.3. These are all set in design view in VS.NET IDE, just like rbl1.
So far so good.
However, for reasons that go beyond explaining here, the Items
collection of rbl2 changes depending on the SelectedIndex change event
of rbl1, and these are dynamic.
So, for instance, if I select rbl1.1, then rbl2 is cleared of its Items,
and then rbl2.1, rbl2.2 and rbl2.3 are re-added to it. If I select
rbl1.2, then rbl2 is cleared of its Items, and rbl2.2 and rbl2.3 are
re-added to it. If I select rbl1.3, then rbl2 is cleared of its Items
and rbl2.3 is re-added to it.
This is necessary because there is no rbl2.items[x].visible = false
property available.
So, I need to be able to maintain the viewstate of rbl2, not only in
terms of what the SelectedIndex is for rbl2, but also what items are
actually present.
Maybe you can see my dilemma. I can do something like
ViewState["rbl2SelectedIndex"], but that only works if the Items
collection of rbl2 stays the same. But it doesn't. I might have 1 item
or 2 items or 3 items in rbl2, I don't know for sure in advance. If the
SelectedIndex of rbl1 is 0, then there are 3 items in rbl2, if the
SelectedIndex of rbl1 is 1, then there are 2 items in rbl2, if the
SelectedIndex of rbl1 is 2, then there is only 1 item in rbl2.
So, I need to track the viewstate of rbl2 for both the SelectedIndex AND
the number of items in rbl2.Items, AND tie them together.
If there was a rbl2.Item[x].Visible property, I would just set that to
false and not have to worry about making it run-time, but I can't do
that, as far as I can see.
So what do I do?
jdn
Hi jdn,
Thank you for posting in the community! My name is Jeffrey, and I will be
assisting you on this issue.
Based on my understanding, when you dynamic control the radiobuttonlist at
runtime, you meet the problem of viewstate maintaining.
============================================================
I am not very certain that what state of your rbl2 will persist. Actually,
because all the items of rbl2 is cleared and new items are added, so all
its item related state will be re-initialized.
If you want to persist some item-irrespective properties, I think you can
persist it through viewstate freely.(The control's predefined properties
have already been persisted through viewstate)
To persist your customized property through viewstate, do like this:
public int public_property
{
get
{
return ViewState["internal_property"];
}
set
{
ViewState["internal_property"]=value;
}
}
In my test project, I do your program logic like this:
private void rbl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
rbl2 .Items.Clear();
for(int i=0;i<3;i++)
{
rbl2 .Items.Add(new ListItem(rbl1.SelectedItem.Text));
}
}
If your viewstate persistance has other conern, please feel free to tell
me. I will work with you.
=========================================================
Thank you for your patience and cooperation.Hope my reply makes sense to
you.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.