Ok, so I'm creating a custom calendar (the one's I've found for free don't fit my needs or are too clunky and the paid ones are well not free) in ASP.NET. I'm using a number of UpdatePanels to allow for the changing of months and the display of the calendars.
Basically the flow is like this, the upper UpdatePanel contains the three LinkButtons lbPrev, lbCurr, and lbNext and one Label lblYear. lbPrev switches the calendar to the previous month, lbNext to the next month and lbCurr does nothing - I just haven't changed it over to a label yet (I may add something when clicking it - like a monthly display I'm not certain).
When clicking any of these, the UpdatePanel works exactly as it is supposed to, updating only the panel itself and not a full postback.
The second of the UpdatePanels, we'll call it udpCalMain, contains the heart of the calendar (all the dates) this is done via an asp:Placeholder control that has LinkButton dynamically rendered (with their text being a couple of divs and an image).
The idea is that when you click one of the dynamically created date cells on the calendar, the system updates the third UpdatePanel "udpDisplay" with pertinent details from a database for that day.
Now, what happens is that whenever you click any date, the page is forced to do a full postback - I know this is from the fact that a dynamically created LinkButton renders as a simple tag and this automatically forces a postback.
What I've tried to do is create an AsyncPostBackTrigger and attach it for each LinkButton that is dynamically created. However, I cannot find (inside the PlaceHolder control) a listing of the controls and their ids so as that I may attach this trigger.
Any help on doing this or another way of avoiding the full postback would be greatly appreciated.
Here is the code I've used to attach the AsyncPostBackTrigger:
AsyncPostBackTrigger apbtDate = new AsyncPostBackTrigger();
apbtDate.ControlID = "ctl00$cpMain$CalendarBase$ctll01"; //Just an example
apbtDate.EventName = "Click";
udp1.Triggers.Add(apbtDate);
And here is the display code for the UpdatePanels:
<asp:UpdatePanel ID="udp1" runat="server" EnableViewState="True" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<div style="width: 700px; float: left">
<div style="width: 700px; text-align: center">
<asp:Label ID="lblYear" runat="server" />
</div>
<div style="float: left; width: 200px; text-align: center">
<asp:LinkButton ID="lbPrev" runat="server" OnClick="lbPrev_Click" />
</div>
<div style="float: left; width: 300px; text-align: center">
<asp:LinkButton ID="lbCurr" runat="server" />
</div>
<div style="float: left; width: 200px; text-align: center">
<asp:LinkButton ID="lbNext" runat="server" OnClick="lbNext_Click" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="udpCalMain" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<div style="width: 700px; height: 700px">
<asp:PlaceHolder ID="phCalendar" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="udpDisplay" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div style="width: 300px; float: left; height: 35px">
</div>
<div style="width: 300px; float: left">
<asp:Label ID="lblTest" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
Basically, I need a way to create clickable elements inside the Placeholder that will not cause a full Postback. Any help would be greatly appreciated.
Okay, so I stumbled upon the answer. I simply added a ID to the LinkButton in the codebehind, I had not considered this to this point. But, apparently the unnamed (no ID that is) LinkButtons simply triggered a default behavior that caused the full postback. Naming the LinkButton then caused the resulting control in PlaceHolder to function properly and not cause the full postback.