Can the asyncpostbacktrigger of an update panel have two control IDs? - c#

I have a button outside an update panel which controls an update panel very well. I also want another button to update this same update panel when the click event is triggered. How can I achieve this?

You can have multiple triggers registered to a single update panel. Something like the following should work:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

Related

Multiple dynamic LinkButton avoid postback

I have many LinkButton but I want it to have singleOnClick event to all LinkButton since it will do the same thing (and I will just get the value of CommandArgument). My problem is that LinkButton keeps on doing postback which will refresh the page every time I click on a LinkButton.
I tried many solutions such us adding href="#", using OnClientClick="" property on the LinkButton control in asp.net, but what happens is it doesn't trigger the ClickEvent anymore.
Is there other way to achieve this? Or javascript is my only way in solving this problem?
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="panelLinkButton" runat="server" UpdateMode="Conditional">
<triggers>
<asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Click" />
</triggers>
<contenttemplate>
<asp:LinkButton ID="LinkButton6" runat="server" CssClass="btn btn-info" OnClick="lnkAddToGroup_Click"><i class="fa fa-search"></i></asp:LinkButton>
</contenttemplate>
</asp:UpdatePanel>
Try using an UpdatePanel like:
<asp:UpdatePanel ID="u1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lnt" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="lnt" runat="server" onclick="LinkTest_Clkk">LinkButton</asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>

button click event on update panel not firing in multiple user control

I am having an update panel which user control in it
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:SelectionAjax ID="SelectionAjax1" runat="server" />
<ppmp:PinPadModal ID="ppmodal" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
and inside this user control I am calling another two user controls each user control which has its own update panel
// First User Control
<asp:UpdatePanel ID="UpP1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFinalConfirmation" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnFinalConfirmation" runat="server" Text="Confirm" OnClick="btnFinalConfirmation_Click1" />
</ContentTemplate>
</asp:UpdatePanel>
//Second User Control
<asp:UpdatePanel ID="UpPanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="btnConfirmation" runat="server" Text="Confirm" OnClick="btnConfirmation_Click1" />
</ContentTemplate>
</asp:UpdatePanel>
The issue is that button click event is only being fired on the second user control not the first one how should I solve this
Include ScriptManager in your Aspx Page.This ScriptManager control provides support for client-side AJAX features in an AJAX enabled web pages.
<asp:ScriptManager ID="ScriptManager1" runat="server"/>

Update Panel and Timer Not working in list View

Hi I have a list view and I am trying to refresh it using an update panel and a timer for trigger. I have tried everything I know but I can get it to update the Listview, but I used a label to test with Time Now which works. So the update panel and trigger are working, but the listview is not refreshing.
<asp:Timer ID="Timer1" runat="server" Interval="100" OnTick="Timer1_Tick"></asp:Timer>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView2" runat="server" DataSourceID="displayFollowers" DataKeyNames="ProfileId"></asp:ListView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="DataBinding" />
</Triggers>
</asp:UpdatePanel>
You should be calling ListView2.DataBind() in the Timer_Tick event for that to work. It does not automatically refresh once initially bound.

ASP Button Event not firing into UserControl UpdatePanel

I have a page with an UpdatePanel that calls a UserControl with another UpdatePanel. The LinkButton event into the user control UpdatePanel is not firing.
<asp:UpdatePanel ID="updPost" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="linkComment" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:LinkButton ID="linkComment" runat="server"
OnClick="linkComment_Click" OnClientClick="return showCommentBox()"
CssClass="PostComment" Text="Comment" />
</ContentTemplate>
</asp:UpdatePanel>
This code is into a usercontrol called in other page update panel.
Anyone can help me?
Thanks
Please show your markup so we can see how your triggers are defined, you should have at least one trigger, something like so:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="MyButton" EventName="Click" />
</Triggers>
Just to clear up the simple stuff, have you included the ScriptManager tag on your page?
i.e. <asp:ScriptManager ID="ScriptManager1" runat="server" />

A control with ID could not be found for the trigger in UpdatePanel

I have an update panel that has UpdateMode of Conditional and ChildrenAsTriggers set to false. I only want a few controls to cause an asynchronous postback:
<asp:UpdatePanel ID="updPnlMain" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
// ...
<asp:Repeater ID="rptListData" runat="server">
<ItemTemplate>
<asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ItemTemplate>
</asp:Repeater>
// ...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I am getting the following error when I try and load this page:
A control with ID 'btnAddSomething' could not be found for the trigger in UpdatePanel 'updPnlMain'.
Since my btnAddSomething control is in a repeater and might not be there right away it acts like it is nonexistent. How can I get around this?
Because your control is in the repeater control and it is out of scope to the Trigger collection. By the way you don't need to add trigger because your button control is already in the UpdatePanel, it will update when you click the button.
Edit: There is a solution if you really want to update your updPnlMain updatepanel. You can put in another updatepanel and put your button in that panel. e.g.
<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
<asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ContentTemplate>
and then simply call the updPnlMain.Update(); method in btnAddSomething_Click event.
It will actually do what you are looking for :)

Categories

Resources