Hi,
I've used this site for reference many times (coz i'm that good!) but this is my first post, so thanks for all the help guys!
Anyway...
I have a page with a repeater control. inside the repeater, i have an updatepanel (i don't need the whole repeater refreshed), and inside that, i have 2 checkboxes that i want to be mutually exclusive!
straightforward huh? er...no!!
adding the MutuallyExclusiveCheckBoxExtender to the panel at Design time causes ALL the checkboxes to uncheck when you click on one, and i can't seem to add the MECE's dynamically at runtime - when i click, nothing happens.
Here's some code for you... it's placed inside Repeater_ItemDatabound
//Check the boxes depending upon user's role Panel myPanel = e.Item.FindControl("RolePanel")as Panel;if (myPanel !=null) { CheckBox myCbA = myPanel.FindControl("cbAdmin")as CheckBox;if (myCbA !=null) { myCbA.Checked = Roles.IsUserInRole(myUser,"Administrator"); } CheckBox myCbB = myPanel.FindControl("cbUser")as CheckBox;if (myCbB !=null) { myCbB.Checked = Roles.IsUserInRole(myUser,"User"); }//Add some ajax! AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender MeCeA =new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender(); AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender MeCeB =new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender(); MeCeA.ID ="MeCeA" + ItemCount.ToString(); MeCeA.Key ="Roles" + ItemCount.ToString(); MeCeA.TargetControlID = myCbA.ID; MeCeB.ID ="MeCeB" + ItemCount.ToString(); MeCeB.Key ="Roles" + ItemCount.ToString(); MeCeB.TargetControlID = myCbB.ID; myPanel.Controls.Add(MeCeA); myPanel.Controls.Add(MeCeB); }
and the source... placed inside the RepeaterItem ItemTemplate
<ajax:UpdatePanel ID="UserDetailsUpdatePanel" runat="server" UpdateMode="Always"> <ContentTemplate> <cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lblResponse"> <Animations> <OnLoad> <FadeOut Duration=".5" Fps="20" /> </OnLoad> </Animations> </cc1:AnimationExtender> <div class="RolePanel"> <asp:Panel ID="RolePanel" runat="server"> <asp:CheckBox ID="cbAdmin" runat="server" Text="Administrator" AutoPostBack="true" /><br /> <asp:CheckBox ID="cbUser" runat="server" Text="User" AutoPostBack="true" /><br /> <center><asp:LinkButton ID="lbtnRoles" runat="server" Text="Submit" /></center> <center><asp:Label ID="lblResponse" runat="server" Visible="False" /></center> </asp:Panel> </div> </ContentTemplate> </ajax:UpdatePanel>
I hope someone can help me - this ajax stuff makes my sites look and feel all funky!
TIA
Ché
Hi,
If I understand the question correctly, you want all 2 to be mutually exclusive checkboxes.
Have you tried adding 2 MutuallyExclusiveCheckBoxExtender in design mode and specifying the same key for both of them?
Yep, i tried that, but where it's inside a repeater it clears all the checkboxes including ones in the different repeateritems.
so, i had the brilliant idea of dynamically creating the extenders at runtime and giving each pair a key, also created at runtime so it's different for each repeateritem.
didn't work.*sob*
so then i thought of grabbing each extender as the repeateritem was databound and applying the unique key there...
nope - didn't work!
Take a quick look at this...
once, i thought it'd be simple!!
TIA for any help!!
Ché
Sorted It!!
one of my plans was indeed correct - i didn't set a key in design time, then at runtime, i grabbed the two extenders and set a unique key for them on each RepeaterItem_DataBound.
Job done!!
No comments:
Post a Comment