Linkbutton Click not working in update panel - asp.net

<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" />

Related

Button click event not firing in case of update panel, AsyncPostBackTrigger also defined

I am fetching data from DB and assign it to repeater.
When I click on button event it only goes to page load function but not to the required on-click event.
I am confused as to why this is happening.
And when I comment out repeater its working fine. I don't why it's not working with repeater in page load.
Aspx code:
<form runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" pdateMode="Conditional" ChildrenAsTriggers="true" >
<asp:Button ID="Button2" runat="server" Text="Next Availabilities"
OnClick="Button2_Click" />
<asp:Repeater id="repeater1" runat="server">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=""><%# Eval("Time") %></asp:Label>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID ="Button3" EventName ="Click" />
<asp:AsyncPostBackTrigger ControlID ="Button2" EventName ="Click" />
</Triggers>
</asp:UpdatePanel>
</form>
In your UpdatePanel:
Correct pdateMode to UpdateMode
Remove ChildrenAsTriggers="true"
Add starting tag of <ContentTemplate>
Assign id ID="UpdatePanel1"
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>

UpdatePanel doesn't allow to fire button click inside gridview

I have a gridview and inside that I have below code.
<asp:TemplateField HeaderText="Header 3">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- only your content that needs refreshing goes here -->
<asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
onclick="ButtonAdd_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonAdd" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
I have added update panel because when I click ButtonAdd button data in the gridview has been removed. But after I added below code button click event doesn't fire. Please suggest solution.
Please place your whole gridview inside update panel and remove update panel inside and try..
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gridview1" runat="server" >
</asp:GridView>
</ContentTemplate>
<Triggers>
</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.

How to update the controls present in two different update panels using the click event of two different buttons

I am quite new to learning asp.net, so the question that I am asking may sound quite basic but I still need an answer as I am doing r&d with some of the toipcs.
I have 2 update panels in my page. Each contains a label. There are two buttons on my page, on the click event of the first button the label in the first update panel should get updated. On the click of the second button the label in the second update panel should get updated.
However when I click any of the two buttons both the labels get updated.
In the load event of the page the foll code is written
Label2.Text = DateTime.Now.ToString();
Label3.Text = DateTime.Now.ToString();
The code for both the update panel is as follows:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID= "Button1" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="click" />
</Triggers>
</asp:UpdatePanel>
Remove the code from the page_load method and place it in the event of each of the buttons. So for button1 you put the code that updates label1 and for button2 you put the code that updates the label2.
You don't even need the triggers unless you're doing cross panel events. However, you do need to properly set up your script manager and update panels:
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional" OnLoad="Panel1_Load">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button1"/>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server"
UpdateMode="Conditional" OnLoad="Panel2_Load">
<ContentTemplate>
<asp:Button ID="Button2" runat="server" Text="Button2"/>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Here you'd put your code in Panel1_Load(){} and Panel2_Load(){}.
Notice the settings: EnablePartialRendering="true"
and: UpdateMode="Conditional"
If you don't want the asp:Button controls on your panels, you'd have to put them somewhere that would block their normal full post-back behavior.

ASP.NET HyperLink as updatepanel trigger

I want to trigger my updatepanel change when I click on a HyperLink But I get an error saying:
Control with ID 'X' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.
If I use ASP Button, then everything works correctly
My code:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateButton2" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptDossiers" runat="server">
<ItemTemplate>
...
</ItemTemplate>
</asp:Repeater>
<asp:HyperLink NavigateUrl="#" runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click">
Tous les Dossiers
</asp:HyperLink>
<%--<asp:Button runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click" text="Update" />--%>
</ContentTemplate>
</asp:UpdatePanel>
Any suggestions?
Thanks
There is no Click event handler that is tied to the Hyperlink control, you have to use LinkButton Instead

Resources