I can not call javascript function after page load inside update panel:
Here is my UpdatePanel:
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode ="Conditional" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonLoadGridView" />
</Triggers>
<ContentTemplate>`
My Button:
protected void ButtonLoadGridView_Click(object sender, EventArgs e)
{
GridView1.DataSource = "dsData";
GridView1.DataBind();
}
Here is javascript function:
window.onload = function ti() {
document.getElementById('<%= Label_Clients.ClientID %>').scrollIntoView({ behavior: 'smooth' });
alert("You data is loaded');
}
I have tried this:
<script>
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(windows.onload;
</script>
The problem is that after loading gridview on button click will not call javascript windows.onload function just only when use PostBackTrigger instead of AsyncPostbackTrigger please help me!
2
Answers
The simples solution would be to create a separate function that is called on page load and on UpdatePanel load.
ps you have a double and single quote in the
alert()
part.ok, so with a update panel, then only "part of" the page goes through the standard page life cycle.
So, your idea to "attach" the event using GetInstance looks to be the correct road.
I would try this syntax:
The above should trigger/run your "MyFunction".