UpdatePanel doesn't allow to fire button click inside gridview - asp.net

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>

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>

UploadFile prevent page postback

My project is a Asp.Net project. The code is written in vb.net.
There are file-upload and a gridview with this TemplatesField:
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<a onserverclick="fnEditWork" class="AEditWork" href='<%#Eval("WorkID")' runat="server" id="EditWork"></a>
</ItemTemplate>
<ItemStyle Width="30px" />
</asp:TemplateField>
in this situation the file-upload works but the anchor does not fire post-back. (the 'fnEditWork' function on onserverclick does not fire.) But when I comment the file-upload code out then fnEditWork function fires.
How can I make it work?
You can do it with AJAX.
Put something like that arround it
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostbackTrigger ControlID="AEditWork" EventName="onserverclick" />
</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.

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.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