Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to trigger updatepanel within a javascript function

i have an updatepanel in my asp.net web page. I want to trigger the updatepanel within a javascript function insead of triggering with a button.
In order to do that, i used __doPostBack('myUpdatePanel', ''); function. But i think it causes the whole page postback. My document.ready function is also executed when i call this function. I may be missing some points.
Is there any other way to trigger updatepanel within a javascript function?

like image 283
Fer Avatar asked Jul 28 '11 08:07

Fer


People also ask

What is trigger in UpdatePanel?

Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their AutoPostBack property set to true.

What is postback trigger in UpdatePanel?

AsyncPostBackTrigger - use these triggers to specify a control within or outside of the UpdatePanel that, when clicked, should trigger a partial page postback. PostBackTrigger - use these triggers to have a control within the UpdatePanel cause a full page postback rather than a partial page postback.

How many different types of triggers are there in the UpdatePanel control?

Answer: There are 2 types of triggers.

How does UpdatePanel work in asp net?

UpdatePanel controls are a central part of AJAX functionality in ASP.NET. They are used with the ScriptManager control to enable partial-page rendering. Partial-page rendering reduces the need for synchronous postbacks and complete page updates when only part of the page has to be updated.


2 Answers

I think if you put a hidden button inside the update panel and you can use the javascript to fire the click of this button, it will do what you want.

<script type="text/javascript">
        function Update_UpdatePaanel() {
            document.getElementById('<%= YourButton.ClientID %>').click()
        }
    </script>

The button MUST be inside a hidden div and DON'T set visibile="false" because if you set it to false, the control will not render and the javascript will produce errors.

<div style="display:none">
        <asp:Button ID="YourButton" runat="server" />
    </div>
like image 178
Samir Adel Avatar answered Sep 19 '22 12:09

Samir Adel


Just create a javascript function and execute the generated postback event:

<%=ClientScript.GetPostBackEventReference(myUpdatePanel, "")%>

The above statement is put on your aspx page, and it references the exact same code generated from the server to cause a postback for your panel. You can use it by putting it inside a function on the client side:

function fncUpdatePanel () {
    <%=ClientScript.GetPostBackEventReference(myUpdatePanel, "")%>;
}

Then you can attach that function to any event on your page (even a mouseover event). This example uses a server side to attach the event:

myUpdatePanel.attributes('onmouseover', 'fncUpdatePanel()')
like image 38
rkw Avatar answered Sep 22 '22 12:09

rkw