Showing posts with label areas. Show all posts
Showing posts with label areas. Show all posts

Saturday, March 24, 2012

Triggering Update Panel from Dynamically Built Triggers

I have a page which has two content areas (Left, Center). The Left hand content contains two repeaters, both of which have an imagebutton who's itemcommand triggers an update of the content in the Center area. The Center Area has an update panel in it. The triggers are dynamically generated because the repeaters are in panels, and I needed to use the findcontrol() command to get access to them.

Code works great on my laptop (localhost), gives an error when I move it to the server. Error is:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing this request on the server. The status code returned from the server was: 500.

Here's my UpdatePanel:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Repeater ID="rMain" DataSourceID="srcMain" OnItemCommand="rmain_itemCommand" runat="server"> <ItemTemplate> <asp:Label ID="lblTitle" Text='<%#Eval("Description")%>' runat="server" CssClass="verorangeHeader" /><asp:Label ID="ProductID" runat="server" Text='<%# Eval("idProduct") %>' Visible="false"></asp:Label><asp:Label ID="lblSKU" runat="server" Text='<%# Eval("Sku") %>' Visible="False" /><br /><br /> <table border="0" cellpadding="1" cellspacing="1"> <tr> <td > <asp:Label ID="lblDetails" Text='<%#Eval("Details")%>' runat="server" CssClass="ver11bluebold" /> </td> <td ><img src='<%# formatPhoto(Eval("ImageURL")) %>' /></td> </tr> <tr> <td colspan="2" align="right" valign="top">Priced from: <asp:Label ID="lblPrice" Text='<%# formatPrice(Eval("Price")) %>' runat="server" CssClass="verorange" />   <asp:ImageButton ID="btnSpecifications" ImageURL="images/btn_specifications.gif" runat="server" /><asp:ImageButton ID="btnPhotoGallery" ImageURL="images/btn_photo-gallery.gif" runat="server" /><asp:ImageButton ID="btnBuyNow" ImageURL="images/buy-bm-clear.gif" runat="server" CommandName="Update" /></td> </tr> </table></ItemTemplate></asp:Repeater></ContentTemplate></asp:UpdatePanel>

Here's the code that creates the triggers:

Private Sub Page_Init(ByVal senderAs Object,ByVal eAs EventArgs)Handles MyBase.Init'Add TriggersDim ap1As AsyncPostBackTrigger =New AsyncPostBackTrigger()Dim ap2As AsyncPostBackTrigger =New AsyncPostBackTrigger() ap1.ControlID = pnlProduct1.FindControl("rY5").UniqueID ap1.EventName ="ItemCommand" ap2.ControlID = pnlProduct2.FindControl("r52").UniqueID ap2.EventName ="ItemCommand" UpdatePanel1.Triggers.Add(ap1) UpdatePanel1.Triggers.Add(ap2)End Sub

Any suggestions?

Jennifer

Take a look at this post...http://forums.asp.net/p/1139950/1831145.aspx

-Damien


Got it fixed. It was actually related to a bug in my Master Page!

Thanks for the help!

Jennifer


To fix this problem, you can add the follow code in your web.config

<system.web>
<pages validateRequest="false">
</system.web>.

Wednesday, March 21, 2012

trouble finding a sample using usercontrols and updatepanels

Hi all,

We have created a menu system primairy based on inserting usercontrols inside one single designed page with several areas's. This works very nice for our sites. Of coarse postback occurs on every click or change.

Some functionality inside usercontrols do a lot of postback, so I would be nice to use the update panel for this type of change.

When trying to implement this I ran into all sorts of trouble, so my first step is to hit this forum. From what i find i'm not the only one having some trouble using usercontrols in combination with the update panel.

So question: Does anyone have a working sample which i could have a look at. Probably can't use it 1 on 1 but well it would a nice starting point.

thanks,

-- jan willem

ps. Does anyone notice .. that all the the ajax stuff (including of coarse atlas) looks REAL nice but when u start to implement it it does realy really takes a lot of time learning to program again :-) Well it's new (ehh well kinda), better and customers do love it.

I wrote a sample to have a test with Ajax and User Control.

http://www.box.net/public/static/q4ltbl5an9.zip

It's simple and straight forward:

1. One user control is linkbutton group, auto generated during runtime;

2. Another user control is to display information according to the user control above;

3. Event subscription is used for information delivery.

4. The link which clicked should be set into different style.

Hope it's helpful.

This was researched days before, now I'm running into the problem of Atlas in live.com. It seems doesn't work with EFP at all!


Thanks for the sample it is usefull!

The only trouble is that the atlas controls (scriptmanager, updatepanel) are still created in the page and not in the usercontrol.

I've created a very simplistic sample of what i'm looking for. Just a page and a usercontrol. I put them in the link below.

http://www.bataviagroep.nl/sampleAtlasUC.zip

- default.aspx --> no atlas, just page and usercontrol doing what it should do .. handling click
- atlas-page.aspx --> same as above, all in one page using atlas and working fine (i added the picture so it's very clear that only the notfication changes

- default-atlas.apsx (same as the first default.aspx) but with the atlas inserted in the usercontrol. This one throws the following exeption:

"The UpdatePanel 'UpdatePanel1' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template."

For those who don't like downloading stuff from a different server:

default.aspx
<body>
<formid="form1"runat="server">
<div>
<asp:PanelID="panel1"runat="server"/>
</div>
</form>
</body
code behind:
ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

panel1.Controls.Add(Page.LoadControl("~/uc-atlas.ascx"))

EndSub

The usercontrol uc.ascx
<asp:LinkButtonID="LinkButton1"runat="server">click A</asp:LinkButton>
<asp:LinkButtonID="LinkButton2"runat="server">click B</asp:LinkButton>
<br/><br/>
<asp:LabelID="Label1"runat="server"Text="Label">not clicked</asp:Label
code behind:

ProtectedSub LinkButton1_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles LinkButton1.Click

Label1.Text ="clicked A"

EndSubProtectedSub LinkButton2_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles LinkButton2.Click

Label1.Text =

"clicked B"EndSub

The same user control but then with atlas stuff added:

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true">

</atlas:ScriptManager>

<asp:LinkButtonID="LinkButton1"runat="server">click A</asp:LinkButton>

|

<

asp:LinkButtonID="LinkButton2"runat="server">click B</asp:LinkButton>

<

br/>

<

br/>

<

atlas:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:LabelID="Label1"runat="server"Text="Label">not clicked</asp:Label></ContentTemplate><Triggers><atlas:ControlEventTriggerControlID="LinkButton1"EventName="Click"/><atlas:ControlEventTriggerControlID="LinkButton2"EventName="Click"/></Triggers>

</

atlas:UpdatePanel>

code behind is the same as above.

--> the above doesn't work and throws an expection.

I would love a sample or idea how to fix this

thanks,

-- jan willem

ps. all the code is in the zipfile


load the custom user control in the Page_Init event, it will work then

wow that worked ...

great that was th easy asnwer i kept missing thanks!

--jw


You might try putting a Placeholder control inside the content template of the UpdatePanel, use FindControl() on the UpdatePanel to locate the Placeholder, and use Placeholder.Controls.Add() to add your dynamically created user control from LoadControl().

The key here is that the container for the user control must exist before OnInit(), and the only way to accomplish this is the declaratively put something there first.

I have gotten this scenario to work. Adding anything directly to the UpdatePanel after OnInitComplete() will not work.