Monday, March 26, 2012

Calling a control on another contentPlaceHolder...

Hi all,

I could not find an answer when I searched, but I assume this can be done. I'm fairly new to AJAX, but here is what I'm trying to do. I have 2 repeaters on my page. They are on seperate content panels. I have the first one set as the trigger for the second one. If I put them on the same contentPlaceHolder, this works great, but when I move the first repeater to another place holder, it blows up because it cannot find the repeater. Is there a way I can reference the first repeater if it is on another place holder?

Here is my code. :

<asp:Content ID="leftSide" runat="server" ContentPlaceHolderID="leftOfPage">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<HeaderTemplate>
<table cellpadding="0" border="1">
<tr>
<th>Header Values</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>ItemValues</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>

<asp:ObjectDataSource ID="ObjectDataSource1" *rest of parameters here*>
</asp:ObjectDataSource>
</asp:Content>

<asp:Content ID="rightSide" runat=server ContentPlaceHolderID="rightSideOfPage">
<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="updateOnClick" runat="server" EnableViewState="true">
<ContentTemplate>
<asp:Repeater ID="Repeater2" runat="server">
<HeaderTemplate>
<table cellpadding="0" border="1">
<tr><th>Header Values</th></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>Item Values</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Repeater1" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>

Thanks!

Hmm, why do you even use two content for? Why don't you use table or two update panels?

Anyway, try this:

Add a hidden textbox in your second Content. When the repeater from the first content rebind or during it's PreRender, you set a value (any value) inside that hidden textbox.

On your second Content:
Use your trigger to aim at the hidden textbox id.

<Triggers><asp:AsyncPostBackTrigger ControlID="textbox_id" EventName="TextChanged" /></Triggers>


hope it works.

p.s. for debugging, don't hide your textbox, because you want to see if the value is set during the PReRender of the first repeater.


Thanks WishStar. The two content placeholders come from my masterpage. In order to maintain consistency throughout the site, I have 4 content placeholders on my master page. Maybe this is improper use of the masterpages (as I'm quite new to them), but I put one in for the header, footer left and right sides of the page. Using placeholders any page can overwrite them if need be, otherwise they see what is on the masterpage. It actually is working quite smoothly, except the issue outlined above.

I did get around the issue using the FindControl() method, but this means I have a hardcoded control name in my code which will compile whether the control exists or not. I don't like this, so I will try out what you mentioned above. Thanks!

Rubes

No comments:

Post a Comment