Asyncpostback using standard button - c#

Using an update panel I am attempting to perform an Async postback with a standard html button.
I have tried this:
<asp:UpdatePanel runat="server" ID="MyUpdatePanel">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnMyButton" EventName="Click" />
</Triggers>
<ContentTemplate>
<button runat="server" id="btnMyButton">ASyncPostBack</button>
</ContentTemplate>
</asp:UpdatePanel>
AND
<asp:UpdatePanel runat="server" ID="MyUpdatePanel">
<Triggers>
</Triggers>
<ContentTemplate>
<button runat="server" id="btnMyButton">ASyncPostBack</button>
</ContentTemplate>
</asp:UpdatePanel>
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = MyControl.ID;
trigger.EventName = "Click";
MyUpdatePanel.Triggers.Add(trigger);
Judging by my scriptmanager IsInAsyncPostBack value nether of these solutions seem to work.
I am not using a standard ASP.NET button because of issues that jQuery has with it and I am aware that I could put a hidden ASP.NET button inside the page and trigger that but am hoping for a better solution.

Event name should be EventName="onserverclick" instead EventName="Click"

Just to update others, its now works as EventName="serverclick"

Related

Postback Problems by using UpdatePanel

I have Used Asp UpdatePanel On Master Page To stop postback. But now it's Create problem on other pages, such as data fetching in gridview on button click.
<asp:UpdatePanel runat="server" ID="updatePanle1">
<ContentTemplate>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
try this code.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridviewBind();
}
}
<asp:UpdatePanel ID="updatepnl" runat="server">
<ContentTemplate>
---Put Your Grid View Code---
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSubmit" />
</Triggers>
</asp:UpdatePanel>
You could try adding Triggers in your UpdatePanel desgin code here to stop the other events causing postback including button clicks and others. Try something like this :
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="clickEvent" />
</Triggers>
You can also try using PostBackTrigger instead of AsyncPostBackTrigger here incase if it doesnt work out as expected.
<Triggers>
<asp:PostBackTrigger ControlID="Button1" EventName="clickEvent" />
</Triggers>
Hope this helps.
We don't normally use the update panel just to prevent the whole asp.net site from re-loading page / posting back. Client controls (jquery) would still be the best fit. But if you're really curious you might want to grind time learning the lessons in this MSDN link https://msdn.microsoft.com/en-us/library/bb398864%28v=vs.140%29.aspx

How to active AsyncPostBackTrigger in Update Panel?

I created a updatePanel, is include some dropdownlist and a few button and I use AsyncPostBackTrigger for not update all page when the click button or select dropdownlist.
My page structure that an aspx page and also use user control page. I use updatePanel on UserControlPage.
Here is My code and I wish you help me:
<asp:UpdatePanel ID="UpdMonthly" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlSenetIslemleriAlinanUrun1" AutoPostBack="true" OnSelectedIndexChanged="ddlSenetIslemleriAlinanUrun1_SelectedIndexChanged" runat="server"></asp:DropDownList>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="btnKaydet" style="margin:10px ;" Width="100" Height="50" runat="server" Text="Kaydet" OnClick="btnKaydet_Click"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSenetIslemleriAlinanUrun1" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnKaydet" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I have some knowledge on placeholder but when the click dropdown or button, page is postback and placeholder knowledge dissappear.
how to fix postback problem?
Thanks for your answers.

asyncfileupload inside update panel not triggering the upload method

I am having a asyncfileupload inside a update panel, I want to upload the file once when a file is selected , the same code works well outside the update panel but my design is in such a way that I can put this outside the update panel, how can I make this work
<asp:UpdatePanel ID="UP_DDL" runat="server" UpdateMode="Always" Visible="true"
RenderMode="Inline">
<ContentTemplate>
<asp:asyncfileupload id="AFU_Doc" runat="server"
uploadingbackcolor="Yellow" onuploadedcomplete="btnDocUpload_Click"
onclientuploadcomplete="sa" throbberid="spanUploading2" />
<span id="spanUploading2" runat="server">Uploading...</span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AFU_Doc" />
</Triggers>
</asp:UpdatePanel>

AsyncPostBackTrigger is not a known element?

I'm using asp.net and c#, making a page with ajax updatepanels. When I try and insert the trigger element, I get the error message AsyncPostBackTrigger is not a known element. What am I missing?
<asp:UpdatePanel ID="UdpEPL" runat="server" UpdateMode="Conditional"
Visible="False">
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnEplShowSubmit"
EventName="BtnEplShowSubmit_Click"/>
</Triggers>
</ContentTemplate>
</asp:UpdatePanel>
Remove the Triggers section from your ContentTemplate:
<asp:UpdatePanel ...>
<Triggers>
<asp:AsyncPostBackTrigger .../>
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>

Nested UpdatePanel: Why does ChildrenAsTriggers have no effect?

Given a simple example with two nested Update-Panels. They are nested, and each one has a label which is filled with the current time in the code behind. I don't understand why the ChildrenAsTriggers="true" - Property on the outer UpdatePanel has no effect? When I hit the 'Update Nested Panel' - button, the time in the parent UpdatePanel is not updated. But as far as I understand the property, it should be:
<asp:ScriptManager ID="ScriptManager1" runat="server"
onasyncpostbackerror="ScriptManager1_AsyncPostBackError">
</asp:ScriptManager>
<asp:Button ID="ButtonUpdate" runat="server" Text="Update Panel 1"
style="margin-top: 15px" onclick="ButtonUpdate_Click" />
<asp:Button ID="ButtonUpdateNestedPanel" runat="server" Text="Update Nested Panel"
style="margin-top: 15px" onclick="ButtonUpdateNestedPanel_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonUpdate" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" />
<asp:UpdatePanel ID="UpdatePanelNested" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonUpdateNestedPanel" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="LabelNested" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
Thx for any tipps!
sl3dg3
p.s.: code behind:
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
LabelNested.Text = DateTime.Now.ToString();
Label1.Text = DateTime.Now.ToString();
}
protected void ButtonUpdateNestedPanel_Click(object sender, EventArgs e)
{
LabelNested.Text = DateTime.Now.ToString();
Label1.Text = DateTime.Now.ToString();
}
When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel.
http://forums.asp.net/t/1422425.aspx/1
and this should be like...
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonUpdate" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ButtonUpdateNestedPanel" EventName="Click" />
</Triggers>
......
......
I believe that, in order to see the desired effect in action, you should actually add your buttons as children in the content template. The "ChildrenAsTriggers" property only applies to direct children of the "ContentTemplate" block.
ChildrenAsTriggers="true"
Set the ChildrenAsTriggers property to true if you want postbacks from immediate child controls of the UpdatePanel control to cause an update of the panel's content. Child controls of nested UpdatePanel controls will not cause an update of the parent UpdatePanel control's content unless you call the Update method explicitly or you define the child controls as triggers.

Categories