Labels

Thursday, May 8, 2008

Handle ClientSide onLoad in AJAX

Hi,

See my earliar post on the same.

We oftenly handle the onLoad event in JS. But the moment we include AJAX (Script Manager) in our pages, the onLoad event fires only for the first time and then never. In such cases, we’ll end up with problems. For. E.g Hiding Label on Client load, will fail after the first load event .

To handle this, need is to introduce the load handler in AJAX, rather than the regular one. Here is the code.

<asp:ScriptManager ID="scmObjectAssignment" runat="server">

</asp:ScriptManager>

<script language="javascript" type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_pageLoaded(pageLoaded);

function pageLoaded(sender, args)

{

var element = window.document.getElementById('lblName');

if(element != null)

{

lblName.style.Display = ‘none’;

}

}

</script>

Thanks & Regards,

Arun Manglick || Senior Tech


No comments:

Post a Comment