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
Related
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>
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>
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>
<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" />
Im trying tp upload more than one image, and when each one I upload I will show it in a repeater, but in the code behind the FileUpload1.HasFile is always False , this is a piece of my code :
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Repeater ID="rpUploadedImages" runat="server">
<ItemTemplate>
<img src='../Images/<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>'/><br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnupload" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />
The FileUpload control does not work with UpdatePanel, you will need to do a full post back to get the file on the server... Now there are a lot of tricks to make it ajaxy...
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
Another tricky way is to create iframe with fileupload + submit button(or some trigger) inside your main form. iframe will postback with no effect to main page.