Showing posts with label event. Show all posts
Showing posts with label event. Show all posts

Wednesday, March 28, 2012

Multiple UpdatePanels, Multiple Page_Loads

I have two UpdatePanels which fire when a Click event executes on my page. I get two Page_Load events firing because the two update panels are triggered.

Is there a way to run the Page_Load only once but have both panels update?

Thanks :)

Hello,

Do you want to update both the update panels?

You can set UpdateMode="Conditional" for the update panel and can add a AsyncPostBackTrigger for the update panel

<asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />

Thanks,

Deepesh Verma


I have my update panels set up like you mentioned however I still get the double page_load.

Update panel 1 and Update panel 2 have the following trigger defined:

<asp:asyncpostbacktrigger controlid="btnSearch" eventname="Click" />

If I remove the trigger from the second Update panel then I will get only one page_load, however since I need to update the second update panel I tried to do it through code like this:

up2.Update();

However this also causes the Page_Load to fire again. Any other ideas?


Hello,

This seems that you have two different update panel and for both you have sameasyncpostbacktrigger.

If this is the case then you can have only one update panel to do that.

Thanks,

Deepesh Verma


SuperGhost:

However this also causes the Page_Load to fire again. Any other ideas?

Are you sure that Page_Load is fired twice?

I've made a simple example and Page_Load is fired only once, it shouldn't depend on how many up are updating...

(

Also works when you set the same trigger

<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn" EventName="click" />
</Triggers>

for each up, and won't call this.up2.update( ) in the server side click event

)

aspx:

<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXCTPEnabledWebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="up1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btn" runat="server" Text="test" />
<%= "Load count" + this.LoadCount.ToString( )%>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<%= "Load count" + this.LoadCount.ToString( )%>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Code-behind:
 
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace AJAXCTPEnabledWebApplication1
{
public partialclass _Default : System.Web.UI.Page
{
private int m_LoadCount = 0;

/// <summary>
/// Gets or sets LoadCount (this property is stored/retrived using the viewstate).
/// </summary>
public int LoadCount
{
get
{
return (int )(this.ViewState["m_LoadCount" ] ?? m_LoadCount );
}
set
{
this.ViewState["m_LoadCount" ] = m_LoadCount =value;
}
}

protected override void OnInit( EventArgs e )
{
base.OnInit( e );

this.btn.Click +=new EventHandler( btn_Click );
}

private void btn_Click(object sender, EventArgs e )
{
this.up2.Update( );
}

protected void Page_Load(object sender, EventArgs e )
{
this.LoadCount++;
}
}
}

 

Monday, March 26, 2012

Must Click Twice for Event to Fire

I have an GridView with an Select link on each line. The link brings up a modal popup for editing data. The GridView is inside an updatepanel.

Everything works great, except for some reason, I have to click the Select link twice for the event to fire. The first click does nothing...does not enter the

SelectedIndexChanged event at all.

Anyone know why?

Wanna post your HTML here so we can take a peek?

WS


Sure here you go..

<%

@.ControlLanguage="vb"AutoEventWireup="false"Codebehind="Packer.ascx.vb"Inherits="WDE.Packer" %>

<%

@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="ajaxToolkit" %>

<

divid="PackerUpdatePanel"><asp:UpdatePanelID="UpdatePanelPackers"runat="server"UpdateMode="Conditional"><ContentTemplate><asp:PanelID="PanelPackersHeader"runat="server"CssClass="collapsePanelHeader"Height="30px"><divstyle="padding: 5px; vertical-align: middle;"><divstyle="float: left;"><asp:LabelID="LblPackers"runat="server"Text="Packers"></asp:Label></div><divstyle="float: left; margin-left: 5px;"><asp:LabelID="LblPackersCount"runat="server"></asp:Label></div><divstyle="float: right; vertical-align: middle; cursor: hand"><asp:ImageButtonID="ImageExpand"runat="server"ImageUrl="~/images/expand_blue.jpg"/></div><divstyle="float: right; margin-right: 20px;"></div></div></asp:Panel><asp:PanelID="PanelPackersViewDetails"runat="server"Height="100%"Width="100%"Wrap="False"><tableid="border"width="100%"cellpadding="0"cellspacing="0"><tr><tdclass="addHeader"><divstyle="float: right; margin-right: 1px;cursor: hand"><asp:LinkButtonID="HyperLinkAddPacker"runat="server"OnClick="HyperLinkAddPacker_Click"ForeColor="White"CssClass="hyperlinkNoLine">Add New Packer</asp:LinkButton></div></td></tr><tr><td><asp:GridViewID="packerGrid"runat="server"CellPadding="4"DataSourceID="PackersXmlDataSource"Width="100%"ForeColor="#333333"AutoGenerateColumns="False"GridLines="None"OnSelectedIndexChanged="packerGrid_SelectedIndexChanged"><FooterStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/><RowStyleBackColor="#F7F6F3"ForeColor="#333333"/><EditRowStyleBackColor="#999999"/><SelectedRowStyleBackColor="#E2DED6"Font-Bold="True"ForeColor="#333333"/><PagerStyleBackColor="#284775"ForeColor="White"HorizontalAlign="Center"/><HeaderStyleBackColor="#5D7B9D"Font-Bold="True"ForeColor="White"/><AlternatingRowStyleBackColor="White"ForeColor="#284775"/><Columns><asp:CommandFieldShowSelectButton="True"SelectText="Edit"/><asp:BoundFieldDataField="packerDate"HeaderText="Date"SortExpression="packerDate"><ItemStyleHorizontalAlign="Left"/><HeaderStyleHorizontalAlign="Left"/></asp:BoundField><asp:BoundFieldDataField="packerOperation"HeaderText="Operation"SortExpression="packerOperation"><HeaderStyleHorizontalAlign="Left"/><ItemStyleHorizontalAlign="Left"/></asp:BoundField><asp:BoundFieldDataField="packerCode"HeaderText="Code"SortExpression="packerCode"><HeaderStyleHorizontalAlign="Left"/><ItemStyleHorizontalAlign="Left"/></asp:BoundField><asp:BoundFieldDataField="packerDepth"HeaderText="Depth"SortExpression="packerDepth"><HeaderStyleHorizontalAlign="Left"/><ItemStyleHorizontalAlign="Left"/></asp:BoundField><asp:CommandFieldButtonType="Image"DeleteImageUrl="~/Images/DELETE.jpg"ShowDeleteButton="True"/></Columns></asp:GridView></td></tr></table></asp:Panel><ajaxToolkit:CollapsiblePanelExtenderID="CollapsiblePanelExtenderPackers"runat="Server"TargetControlID="PanelPackersViewDetails"ExpandControlID="ImageExpand"CollapseControlID="ImageExpand"Collapsed="True"ExpandedImage="~/images/collapse_blue.jpg"CollapsedImage="~/images/expand_blue.jpg"ImageControlID="ImageExpand"SuppressPostBack="true"/></ContentTemplate></asp:UpdatePanel>

</

div>

<

divid="PackersMaintenancePanelDiv"><asp:ButtonID="FakePackerTarget"runat="server"Style="display: none"></asp:Button><ajaxToolkit:ModalPopupExtenderID="ModalPopupAddEditPacker"runat="server"TargetControlID="FakePackerTarget"PopupControlID="PanelPackerAddEdit"BackgroundCssClass="modalBackground"DropShadow="false"CancelControlID="btnCancel"/><asp:PanelID="PanelPackerAddEdit"runat="server"Width="45%"Wrap="False"Style="display: none"BorderStyle="Solid"BorderColor="#6b8aad"><asp:UpdatePanelID="UpdatePanelPackerModalPopup"runat="server"><ContentTemplate><tableid="AddPackTable"runat="server"style="width: 100%; background-color: white;"><tr><tdcolspan="3"style="font-size: 10pt; background-color: #6b8aad; color: White"><asp:LabelID="lblPackerHeader"runat="server"Text="Packer"></asp:Label></td></tr><tr><td><asp:LabelID="lblPackerDate"runat="server"Text="Date:"Width="78px"></asp:Label><br/></td><td><asp:TextBoxID="txtPackerDate"runat="server"></asp:TextBox><spanstyle="font-size: 10pt; color: #ff0033">* </span><asp:ImageButtonID="ImageBtnCalendar"runat="server"ImageUrl="~/Images/CalendarButton.gif"/><ajaxToolkit:PopupControlExtenderID="PopupControlExtenderPackerDate"runat="server"TargetControlID="ImageBtnCalendar"PopupControlID="PanelCalendar"Position="Bottom"/><spanstyle="font-size: 10pt">(yyyymmdd)</span></td><td><asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="txtPackerDate"ErrorMessage="RequiredFieldValidator"Display="Dynamic">Date is required.</asp:RequiredFieldValidator></td></tr><tr><td><asp:LabelID="lblPackerOperation"runat="server"Text="Operation:"></asp:Label></td><td><asp:RadioButtonListID="rblPakerOperation"runat="server"RepeatDirection="Horizontal"><asp:ListItemSelected="True"Value="P">Pulled</asp:ListItem><asp:ListItemValue="S">Set</asp:ListItem></asp:RadioButtonList></td><td></td></tr><tr><td><asp:LabelID="lblPackerCode"runat="server"Text="Code:"></asp:Label></td><td><asp:TextBoxID="txtBoxPackerCode"runat="server"></asp:TextBox><asp:ButtonID="btnPackerCodes"runat="server"Text=".."/><ajaxToolkit:PopupControlExtenderID="PopupControlExtenderPackerCodes"runat="server"TargetControlID="btnPackerCodes"PopupControlID="PanelPackerCode"Position="Bottom"/></td><td></td></tr><tr><td><asp:LabelID="lblPackerDepth"runat="server"Text="Depth:"></asp:Label></td><td><asp:TextBoxID="txtboxPackerDepth"runat="server"MaxLength="7"></asp:TextBox>mkb<spanstyle="font-size: 10pt; color: #ff0033">*</span></td><td><asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="txtboxPackerDepth"ErrorMessage="RequiredFieldValidator"Display="Dynamic">Depth is required.</asp:RequiredFieldValidator></td></tr><tr><tdcolspan="3"><hr/></td></tr><tr><td><spanstyle="color: #ff0033"><spanstyle="font-size: 10pt; color: #ff0033">*</span></span>-Required</td><td></td><tdstyle="width: 100%"><asp:ButtonID="btnPackerAddOk"runat="server"Text="Ok"/><asp:ButtonID="btnCancel"runat="server"Text="Cancel"OnClick="btnCancel_Click"CausesValidation="False"/></td></tr></table></ContentTemplate></asp:UpdatePanel></asp:Panel>

</

div>

<

divid="PanelCalendarDiv"><asp:PanelID="PanelCalendar"runat="server"CssClass="popupControl"Style="z-index: 10002"><asp:UpdatePanelID="UpdatePanelCalendar"runat="server"UpdateMode="Always"><ContentTemplate><center><asp:CalendarID="Calendar1"runat="server"BackColor="White"BorderColor="#999999"CellPadding="1"DayNameFormat="Shortest"Font-Names="Verdana"Font-Size="8pt"ForeColor="Black"Width="160px"OnSelectionChanged="Calendar1_SelectionChanged"><SelectedDayStyleBackColor="#666666"Font-Bold="True"ForeColor="White"/><TodayDayStyleBackColor="#CCCCCC"ForeColor="Black"/><SelectorStyleBackColor="#CCCCCC"/><WeekendDayStyleBackColor="#FFFFCC"/><OtherMonthDayStyleForeColor="#808080"/><NextPrevStyleVerticalAlign="Bottom"/><DayHeaderStyleBackColor="#CCCCCC"Font-Bold="True"Font-Size="7pt"/><TitleStyleBackColor="#999999"Font-Size="7pt"BorderColor="Black"Font-Bold="True"/></asp:Calendar></center></ContentTemplate></asp:UpdatePanel></asp:Panel>

</

div>

<

divid="PanelPackerCodeDiv"><asp:PanelID="PanelPackerCode"runat="server"CssClass="popupControl"Style="z-index: 10003"><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:RadioButtonListID="RblPackerCodes"runat="server"OnSelectedIndexChanged="RblPackerCodes_SelectedIndexChanged"AutoPostBack="true"><asp:ListItemValue="1">1 - Packer</asp:ListItem><asp:ListItemValue="2">2 - Bridge plug or whipstock packer</asp:ListItem><asp:ListItemValue="3">3 - Cement retainer</asp:ListItem><asp:ListItemValue="4">4 - Through tubing packer</asp:ListItem><asp:ListItemValue="5">5 - Through tubing bridge plug</asp:ListItem></asp:RadioButtonList></ContentTemplate></asp:UpdatePanel></asp:Panel>

</

div>

<

asp:XmlDataSourceID="PackersXmlDataSource"runat="server"DataFile="~/XML/Packers.xml">

</

asp:XmlDataSource>

<

asp:ObjectDataSourceID="PackersObjectDataSource"runat="server"DataObjectTypeName="Packer"DeleteMethod="DeletePacker"SelectMethod="GetPackers"TypeName="WellOperation"UpdateMethod="UpdatePacker"></asp:ObjectDataSource>

I'm having the same problem and have tried for 2 weeks to resolve without success. I have converted to the RC AJAX - still same issue. I have suspected that the problem revolves around a custom user control that is on my form. It is simply an alphabet selector with 26 letters as links.

I have traced the events and on the first click, the code goes as far as the constructor code for the user control and then simply stops. But then, as Janet wrote, the second click works just fine.

Mutiple update panel - How to bind trigger event for control which is inside of other upda

Hi,

Thanks for visitng my problem.

I have 3 update panels. in first update panel U1 I have text box T1 and drop dwonbox D1.In second update panel U2 i have only drop down box D2. and in third update panel U3 i have a treeview T1.

I want that When I change selection of D1 in U1, it triiger events for D2 in U2 and T1 in U3. But when I try to bid U2 with D1 change event it does not show show D1 namein triiger control names. Rather it shows U1 panel name. Sam case is for T1 in U3. So my qiestion is : "HOW TO BIND TRIGGER WITH CONTROL WHICH IS INSIDE OF OTHER UPDATE PANEL?"

Looking for your Help.

Thanks,

John

Hi John,

I think the easiest solution would be to place one UpdatePanel around all three controls. If this doesn't work for you, perhaps you could post asmall code sample showing what you already tried.

Thanks,
Ted