Showing posts with label triggers. Show all posts
Showing posts with label triggers. Show all posts

Wednesday, March 28, 2012

Dynamic Content events needed as Trigger events

Is there a way to add triggers at runtime? I have a bunch of dynamic images that show that I want to add the click events as triggers to update a larger image. Thanks.

I don't think you can add triggers dynamically (maybe it's possible, I don't see a way however).

The best way to procede depends on your needs. If *all* you need is your UpdatePanel to update() when some image is clicked and you don't know what / how many images at runtime, you could just dynamically add the image controls to the UpdatePanel's container controls, and give each image an onclick attribute with a postback reference. Something like this:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Image Image1 = new Image(); UpdatePanel1.ContentTemplateContainer.Controls.Add(Image1); Image1.ID = "Image1"; Image1.ImageUrl = "img.png"; Image1.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(Image1, "Image1PostBack")); }</script><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> asdf </ContentTemplate> </asp:UpdatePanel> </form></body></html>
 

If the dynamic images need to be outside the UpdatePanel you want to trigger - does it matter to your update which dynamic image was clicked? Depending on that, there are other possibillities.

Ben


Ben,

Thanks for the post. I figured it out. You can add triggers to the updatepanel.

Dim x As New AsyncPostBackTriggerx.ControlID = <name of control that will be doing the update>x.EventName = "Click"update.Triggers.Add(x)

Just make sure this runs even after a post back.

Wednesday, March 21, 2012

DropDownList causes a full page postback instead of only updating the UpdatePanel

I have a code for updating a DropDownList with items whenever another DropDownList triggers a SelectedIndexChanged event.

When I select an item in the DDLSelect dropdown, it causes a full page postback instead of just updating the UpdatePanel. This problem only occurs when I try to implement it in an existing project, and it works fine when if I try it in a new project.

I've updated my Web.config file to make my project compatible with AJAX, so I don't believe that's the problem.

I should add that I'm trying to use this inside an ascx UserControl file, so maybe there are known issues there.

Thanks in advance.

Please post the usercontrol code

OK, problem solved!

It was the Web.config after all. I had this line which caused the problem:

<

xhtmlConformancemode="Legacy"/>

I removed it and everything is fine.

Cheers.

DropDownExtender!

The Toolkit Example is quite simple, my scenario is I have a DropDownList which is binded to a data source! How can I add the triggers for 50+ ListItems of my DropDown?

<Triggers><asp:AsyncPostBackTriggerControlID="Option1"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="Option2"EventName="Click"/>

</Triggers>

I want to basically navigate the dropdownlist using my arrow keys on the keyboard and I have an imagePanel whose Image changes depending upon what item selection on the dropDownlist, right now if I click on the DropDownList I am able to update the ImagePanel, but I want to do this using the arrow keys...

Youre not going to be able to do this in any easy way. It is possible but if you want to make it happen you have to pump out a heap of javascript. If you still want to let me know and Ill try and point you in the right direction.