UpdatePanel AsyncPostbackTrigger not firing - asp.net

I've got a little problem, any help is appreciated.
Situation looks like this:
<asp:UpdatePanel ID="UP_Panel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlSwitch" runat="server" Width="250px" AutoPostback="true"
OnSelectedIndexChanged="ddlSwitch_SelectedIndexChanged">
<asp:ListItem Value="continent" Text="Continent"></asp:ListItem>
<asp:ListItem Value="region" Text="Region"></asp:ListItem>
<asp:ListItem Value="country" Text="Country"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UP_Switch" runat="server" UpdateMode="Conditional">
<ContentTemplate>
// Some content
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSwitch" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
When ddlSwitch selected index change I want to update content inside UP_Switch, but SelectedIndexChanged event doesn't seem to fire. What am I doing wrong?
Thanks in advance!

I have just tested your code and seems to be working with some test modifications: ASPX
<asp:UpdatePanel ID="UP_Panel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlSwitch" runat="server" Width="250px" AutoPostback="true"
OnSelectedIndexChanged="ddlSwitch_SelectedIndexChanged">
<asp:ListItem Value="continent" Text="Continent"></asp:ListItem>
<asp:ListItem Value="region" Text="Region"></asp:ListItem>
<asp:ListItem Value="country" Text="Country"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel ID="UP_Switch" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Literal ID="litUpSwitch" runat="server"></asp:Literal>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSwitch" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
Code behind for ddlSwitch_SelectedIndexChanged:
protected void ddlSwitch_SelectedIndexChanged(object sender, EventArgs e)
{
litUpSwitch.Text = "DDL Switch go activated";
}
Result:

Related

Button click not working inside update panel

When I use Button inside Update panel it doesnot fire click event but outside the update panel it works.
here is the code
<asp:UpdatePanel ID="updatePanel2" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Button ID="btnBlock" class="Button" Text="BlockCalls" runat="server"
onclick="btnBlock_Click" Enabled="True" Width="100px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnBlock" />
</Triggers>
</asp:UpdatePanel>
code for button is
protected void btnBlock_Click(object sender, EventArgs e)
{
CtiWS.CtiWS CtiWS1 = new CtiWS.CtiWS();
Response.Write("<script>alert('"+Convert.ToString(Session["BlockCalls"])+"')</script>");
if (btnBlock.Text == "BlockCalls")
{
btnBlock.Text = "UnBlockCalls";
CtiWS1.BlockCalls("", "", HttpContext.Current.Session["HOSTID"].ToString()); //server block calls
}
else
{
btnBlock.Text = "BlockCalls";
CtiWS1.BlockCalls("", "", HttpContext.Current.Session["HOSTID"].ToString()); //server unblock calls
}
}
Try this
set ChildrenAsTriggers to true and add EventName="Click" in asp:AsyncPostBackTrigger
<asp:UpdatePanel ID="updatePanel2" runat="server" UpdateMode="Conditional"
ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="btnBlock" class="Button" Text="BlockCalls" runat="server"
onclick="btnBlock_Click" Enabled="True" Width="100px" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnBlock" EventName="Click"/>
</Triggers>
</asp:UpdatePanel>

AJAX CalendarExtender refresh update panel

I've added a CalendarExtender to reset the dates of a datasource for a grid view.
Code -
<asp:UpdatePanel ID="UPTabs" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="tbMoveInDate" eventname="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="tbMoveInDate" Width="70px" AutoPostBack="true" runat="server"/>
<asp:CalendarExtender ID="tbMoveInDateCalendarExtender" runat="server" Format="MM/yyyy"
TargetControlID="tbMoveInDate" OnClientHidden="onCalendarHidden" OnClientShown="onCalendarShown" />
<asp:GridView ID="gvMoveins" runat="server" .../>
</ContentTemplate>
</asp:UpdatePanel>
with the intention of forcing the update panel to update when the date is changed.
What am I missing?
Need to use
<asp:PostBackTrigger />
to get the effect I needed.

TextBox.Text returned empty after postback from nested asp:UpdatePanel

This is the code that I have:
<asp:UpdatePanel runat="server" ID="UPnlParent" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div><h3>title</h3></div>
<asp:UpdatePanel runat="server" ID="UPnlChild" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server" ID="Tb1"></asp:TextBox>
<asp:LinkButton runat="server" ID="Btn1" Text="Create" OnClick="Create" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
In the code behind I have a function for an event "Create"
protected void Create(object sender, EventArgs e)
{
string textFromPostBack= Tb1.Text;
//do something...
}
The string is empty.
Thank you for your assistance.
You should add the button as a trigger to the update panel if you want it to trigger a post back:
<asp:UpdatePanel ...>
<ContentTemplate>
blablabla
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Btn1" />
</Triggers>
</asp:UpdatePanel>
More details :Click

Linkbutton Click not working in update panel

<div id="TrainingSearchGridContainer" class="mt_20">
<asp:UpdatePanel runat="server" ID="UpdatePanelCountryRegions" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList runat="server" ID="ProductDropDown"></asp:DropDownList>
<asp:DropDownList runat="server" ID="DateDropDown"></asp:DropDownList>
<asp:DropDownList runat="server" ID="CountryDropDown" AutoPostBack="True" OnSelectedIndexChanged="LoadRegions"></asp:DropDownList>
<asp:DropDownList runat="server" ID="StateDropDown"></asp:DropDownList>
<asp:LinkButton ID="SearchBtn" runat="server" OnClick="StartSearch">
<span class="blueButton2css3"><span class="btnspan">
<asp:Literal ID="SearchButtonText" runat="server"></asp:Literal></span></span>
</asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:asyncpostbacktrigger controlid="SearchBtn" eventname="Click" />
But for some reason when I click on the button nothing happens, If I remove the update panel the button works fine.
The problem is that you are using AsyncPostBackTrigger instead of PostbackTrigger. AsyncPostBackTrigger is used when the control is outside the update panel, your linkbutton is present inside the update panel so you should use PostBackTrigger.
<asp:PostBackTrigger ControlID="SearchBtn" />

ASP timer Control is refreshing the whole page?

I have a ASP timer control which is supposed to run every three minutes. Although I kept the Timer control in an update panel, it is refreshing the whole page every time it runs.
Is there any it only refresh the particular section of the page, not the whole page?
<div>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000" >
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:Timer runat="server" id="UpdateTimer" interval="200" ontick="function" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="label1" />
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
you need to use UpdatePanel Triggers. Conditional Update Panels with triggers, and msdn source. Updatepanel with Triggers
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000"> </asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
Use update panel and add all the control's inside update panel which you don't want to be refreshed or postback by any event

Resources