Showing posts with label events. Show all posts
Showing posts with label events. 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 Events

Hi There,

I started playing ASP.NET AJAX some months ago as part of a Universiy project. I've recently come back to it and have made most of the changes I think I need to make to use the new ASP.NET AJAX beta (I was previously using the Atlas CTP). However, I have a problem with dwopdownlist event names.

I have a basic application that has a drop down list and a repeater. The dropdownlist is bound to the one side of a DB relationship and the repeater is bound to the many. All works fine in terms of displaying the controls on the page but I can't get the repeater control list to change based on the valyue selected in the dropdown list. The last few lines of code within <asp:updatePanel/> are as follows:

<Triggers>

<asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="OnSelectedIndexChange"/></Triggers>

The problem is the EventName attribute not being recognised. I have searched evrywhere for a comprehensive list of Dropdownlist evcent names but I can't find anything. What I have found hasn't worked.

Am I missibg something else or is it simply a case of the dropdownlist event name being incorrect.

Thanks in advance for your help.

Kind Regards

Mike

i was the same question with you before.

try using EventName = "SelectedIndexChanged"

DropDownList and only DropDownList causes Full Page Post Back

I have a radio button list, buttons, a DropDownList within a UpdatePanel.

Buttons, RadioButtonList events work fine doing async request but..the DropDownList events causes a Full Page postback

DroDownList need some additional setting? DropDownList has some ajax limitation ? a bug?

thanks in advance,

Alexander



Can you post your code?


hi,

have you set autopostback = true for dropdown list? try to make it false

thanks,

satish.


I try it and the problem is solved.

but the control doesnt trigger events when "selected item change" and in my case..that's not a wished behavior.

thanks,

Alexander.

PD: I haven't the code now, sorry


I post the .aspx code.

The name of the control tha causes de full page post back is "dropDownListUnits"

thanks.

----------------

<%@.PageLanguage="C#"MasterPageFile="~/SinMenuDerecho.master"AutoEventWireup="true"

CodeFile="PlayerConsole.aspx.cs"Inherits="Player_PlayerConsole"Title="Tablero de Batalla"EnableViewState="true"%>

<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<%@.RegisterAssembly="GMaps"Namespace="Subgurim.Controles"TagPrefix="cc1" %>

<asp:ContentID="Content1"ContentPlaceHolderID="mainContent"runat="Server">

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<divstyle="text-align: center">

<divstyle="text-align: center">

<tablestyle="height: 350px; width: 900px">

<tr>

<tdstyle="width: 871px; vertical-align: top;">

<div>

<cc1:GMapID="GMap1"runat="server"enableServerEvents="True"Height="489px"OnClick="GMap1_Click"

Width="672px"/>

</div>

</td>

<tdstyle="vertical-align: top">

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<contenttemplate>

<TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="WIDTH: 100px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="LblGeneral"runat="server"Width="200px"ToolTip="Informaci¢n General de la Batalla"Text="Batalla"CssClass="headerstyle"></asp:Label></TD><TDstyle="WIDTH: 100px"><asp:ImageButtonid="ImageButtonGeneral"onclick="ImageButtonGeneral_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE></TD></TR><TR><TD><asp:Panelid="PanelGeneral"runat="server"Width="100%"Height="50px">

<tablestyle="width: 100%; height: 100%; text-align: left">

<tr>

<tdstyle="font-size: 10pt; font-family: Verdana; font-weight: bold; width: 34px;

height: 18px;">

Id</td>

<tdstyle="height: 18px">

<asp:LabelID="LblGeneralBatalla"runat="server"></asp:Label>

</td>

</tr>

<tr>

<tdstyle="font-weight: bold">

<spanstyle="font-size: 10pt">Tipo</span>

</td>

<td>

<asp:LabelID="LblGeneralTipoBatalla"runat="server"></asp:Label></td>

</tr>

<tr>

<tdstyle="font-weight: bold">

<spanstyle="font-size: 10pt">Turno</span></td>

<td>

<asp:LabelID="LblGeneralTurno"runat="server"></asp:Label></td>

</tr>

<tr>

<tdstyle="font-weight: bold;">

Estado</td>

<td>

<asp:LabelID="LblGeneralEstado"runat="server"></asp:Label></td>

</tr>

</table>

</asp:Panel><cc1:CollapsiblePanelExtenderid="CollapsiblePanelGeneralExtender"runat="server"ExpandControlID="ImageButtonGeneral"CollapseControlID="ImageButtonGeneral"TargetControlID="PanelGeneral">

</cc1:CollapsiblePanelExtender></TD></TR></TBODY></TABLE><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 100px; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 81px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="LblProximaAccion"runat="server"Width="200px"ToolTip="Pr¢xima Acci¢n"Text="Acci¢n"CssClass="headerstyle">

</asp:Label></TD><TDstyle="WIDTH: 100px"><asp:ImageButtonid="ImageButtonAction"onclick="ImageButton1_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE></TD></TR><TR><TDstyle="VERTICAL-ALIGN: top; WIDTH: 100px"><asp:Panelid="PanelAction"runat="server"Width="100%">

<tablestyle="width: 100%; height: 100%">

<tr>

<tdstyle="vertical-align: top; width: auto; text-align: left;">

<asp:RadioButtonListID="RadioButtonListActions"runat="server"CellPadding="0"CellSpacing="0"

AutoPostBack="True"OnSelectedIndexChanged="RadioButtonListActions_SelectedIndexChanged">

<asp:ListItemEnabled="False">Mover</asp:ListItem>

<asp:ListItemEnabled="False">Atacar</asp:ListItem>

<asp:ListItemEnabled="False"Value="PosicionarSatelite">Posicionar Satelite</asp:ListItem>

</asp:RadioButtonList>

<cc1:CollapsiblePanelExtenderID="CollapsiblePanelActionsExtender"runat="server"

TargetControlID="PanelAction"CollapseControlID="ImageButtonAction"ExpandControlID="ImageButtonAction">

</cc1:CollapsiblePanelExtender>

</td>

</tr>

</table>

</asp:Panel></TD></TR></TBODY></TABLE><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 100px; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="WIDTH: 100px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="lblUnidad"runat="server"Width="200px"ToolTip="Mis unidades"Text="Unidades"CssClass="headerstyle"></asp:Label></TD><TDstyle="WIDTH: 100px"><asp:ImageButtonid="ImageButtonUnidad"onclick="ImageButtonUnidad_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE></TD></TR><TR><TD><asp:Panelstyle="TEXT-ALIGN: left"id="PanelUnidad"runat="server"Width="100%"> <asp:DropDownListid="dropDownListUnits"runat="server"OnSelectedIndexChanged="DropDownListUnits_SelectedIndexChanged"AutoPostBack="True"DataValueField="Id"DataTextField="UnitDescription"DataSourceID="PlayerUnitsDataSource">

</asp:DropDownList><asp:ObjectDataSourceid="PlayerUnitsDataSource"runat="server"TypeName="PlayerUnitsDataSource"SelectMethod="GetPlayerUnits">

<SelectParameters>

<asp:QueryStringParameterDefaultValue="null"Name="battleID"QueryStringField="BattleID"

Type="Int32"/>

</SelectParameters>

</asp:ObjectDataSource> <TABLEstyle="WIDTH: 100%"><TBODY><TR><TDstyle="WIDTH: 100px"><STRONG>Info de la Unidad Seleccionada:</STRONG></TD></TR></TBODY></TABLE><BR/><TABLEstyle="WIDTH: 100%"><TBODY><TR><TDstyle="WIDTH: 37px"><STRONG>ID</STRONG></TD><TDstyle="WIDTH: 100px"><asp:Labelid="LblUnidadID"runat="server"></asp:Label></TD></TR><TR><TDstyle="WIDTH: 37px"><STRONG>Tipo</STRONG></TD><TDstyle="WIDTH: 100px"><asp:Labelid="LblUnidadTipo"runat="server"></asp:Label></TD></TR><TR><TDstyle="WIDTH: 37px"><STRONG>Posici¢n</STRONG></TD><TDstyle="WIDTH: 100px"><asp:Labelid="LblUnidadPosicion"runat="server"></asp:Label></TD></TR></TBODY></TABLE></asp:Panel><cc1:CollapsiblePanelExtenderid="CollapsiblePanelUnidadExtender"runat="server"ExpandControlID="ImageButtonUnidad"CollapseControlID="ImageButtonUnidad"TargetControlID="PanelUnidad">

</cc1:CollapsiblePanelExtender></TD></TR></TBODY></TABLE><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 100px; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="WIDTH: 100px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="LabelPlayers"runat="server"Width="200px"ToolTip="Jugadores de la batalla"Text="Jugadores"CssClass="headerstyle"></asp:Label></TD><TDstyle="WIDTH: 100px"><asp:ImageButtonid="ImageButtonPlayers"onclick="ImageButtonPlayers_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE> </TD></TR><TR><TD><asp:Panelstyle="TEXT-ALIGN: left"id="PanelPlayers"runat="server"Width="100%">

<asp:ListBoxID="ListBoxPlayers"runat="server"DataSourceID="BattlePlayersDataSource"

DataTextField="UserName"DataValueField="PlayerID"></asp:ListBox><asp:ObjectDataSource

ID="BattlePlayersDataSource"runat="server"SelectMethod="GetBattlePlayers"TypeName="BattlePlayersDataSource">

<SelectParameters>

<asp:QueryStringParameterDefaultValue="null"Name="battleID"QueryStringField="BattleID"

Type="Int32"/>

</SelectParameters>

</asp:ObjectDataSource>

</asp:Panel><cc1:CollapsiblePanelExtenderid="CollapsiblePanelPlayersExtender"runat="server"ExpandControlID="ImageButtonPlayers"CollapseControlID="ImageButtonPlayers"TargetControlID="PanelPlayers">

</cc1:CollapsiblePanelExtender></TD></TR></TBODY></TABLE><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 100px; HEIGHT: 33px; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="WIDTH: 100px; HEIGHT: 40px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="LblAlliances"runat="server"Width="200px"ToolTip="Alianzas de la batalla"Text="Alianzas"CssClass="headerstyle"></asp:Label></TD><TDstyle="WIDTH: 100px; HEIGHT: 40px"><asp:ImageButtonid="ImageButtonAlliances"onclick="ImageButtonAlliances_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE></TD></TR><TR><TDstyle="HEIGHT: 69px"><asp:Panelstyle="TEXT-ALIGN: left"id="PanelAlliances"runat="server"Width="100%">

<asp:TreeViewID="TreeViewAlliances"runat="server"ImageSet="Contacts"NodeIndent="10"

AutoGenerateDataBindings="False"EnableClientScript="False"PopulateNodesFromClient="False">

<ParentNodeStyleFont-Bold="True"ForeColor="#5555DD"/>

<HoverNodeStyleFont-Underline="False"/>

<SelectedNodeStyleFont-Underline="True"HorizontalPadding="0px"VerticalPadding="0px"/>

<RootNodeStyleFont-Bold="True"/>

<NodeStyleFont-Names="Verdana"Font-Size="8pt"ForeColor="Black"HorizontalPadding="5px"

NodeSpacing="0px"VerticalPadding="0px"/>

<Nodes>

<asp:TreeNodeText="Alianzas"Value="Alianzas">

<asp:TreeNodeText="Alianza1"Value="Alianza1">

<asp:TreeNodeText="Usuario1"Value="Usuario1"></asp:TreeNode>

</asp:TreeNode>

<asp:TreeNodeText="Alianza2"Value="Alianza2">

<asp:TreeNodeText="Usuario2"Value="Usuario2"></asp:TreeNode>

<asp:TreeNodeText="Usuario3"Value="Usuario3"></asp:TreeNode>

</asp:TreeNode>

</asp:TreeNode>

</Nodes>

</asp:TreeView>

</asp:Panel><cc1:CollapsiblePanelExtenderid="CollapsiblePanelAlliancesExtender"runat="server"ExpandControlID="ImageButtonAlliances"CollapseControlID="ImageButtonAlliances"TargetControlID="PanelAlliances">

</cc1:CollapsiblePanelExtender></TD></TR></TBODY></TABLE><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="VERTICAL-ALIGN: bottom; WIDTH: 100px; TEXT-ALIGN: left"><TABLEstyle="WIDTH: 100%; HEIGHT: 100%"><TBODY><TR><TDstyle="WIDTH: 100px"><asp:Labelstyle="FONT-WEIGHT: bold; FONT-SIZE: 10pt"id="lblSatelite"runat="server"Width="200px"ToolTip="Satelites Disponibles del Jugador"Text="Satelites"CssClass="headerstyle"></asp:Label></TD><TDstyle="WIDTH: 100px"><asp:ImageButtonid="ImageButtonSatelite"onclick="ImageButtonSatelite_Click"runat="server"ImageUrl="~/App_Themes/BattleTheme/collapse.jpg"></asp:ImageButton></TD></TR></TBODY></TABLE></TD></TR><TR><TDstyle="HEIGHT: 69px"><asp:Panelstyle="TEXT-ALIGN: left"id="PanelSatelite"runat="server"Width="100%"> <TABLE><TBODY><TR><TDstyle="WIDTH: 122px; HEIGHT: 16px">Satelites Disponibles</TD><TDstyle="WIDTH: 100px; HEIGHT: 16px"><asp:Labelid="LblSatelliteCantidad"runat="server"></asp:Label></TD></TR><TR><TDstyle="WIDTH: 122px"></TD><TDstyle="WIDTH: 100px"></TD></TR></TBODY></TABLE></asp:Panel><cc1:CollapsiblePanelExtenderid="CollapsiblePanelSateliteExtender"runat="server"ExpandControlID="ImageButtonAlliances"CollapseControlID="ImageButtonAlliances"TargetControlID="PanelSatelite">

</cc1:CollapsiblePanelExtender></TD></TR></TBODY></TABLE><asp:Timerid="Timer1"runat="server"Interval="5000"OnTick="Timer1_Tick"></asp:Timer><BR/>

</contenttemplate>

</asp:UpdatePanel>

</td>

</tr>

</table>

</div>

</div>

</asp:Content>


Have you set the property AutoPostBack = true" for DropDownList

Check this forum

http://forums.asp.net/p/1053484/1493464.aspx