How to push a button from serverside using ScriptManager and UpdatePanel control.
December 10, 2010 Leave a comment
I was playing around with an idea that it could be fun to press client-side logoff button from the server-side. Like if you dont push the logoff button i will push it for you,.. noition..(c: To achive that i devised a way to “inject” javascript in to an UpdatePanel using ScriptManager.. so cool,.. it is kind of nougty i guess..
her’s how it’s done:
aspx
<asp:ScriptManager ID="scmAJAX" EnablePartialRendering="true" runat="server"/> <asp:UpdatePanel ID="upnl_Mask" runat="server" UpdateMode="Conditional" > <ContentTemplate> <asp:label ID="lbl_Mask" runat="server"></asp:label> </ContentTemplate> </asp:UpdatePanel>
aspx.cs
string jscript = @"$(window).ready(function (){ $("".btnLogoff INPUT"")[0].click();});"; ScriptManager.RegisterClientScriptBlock(lbl_Mask, lbl_Mask.GetType(), "youLoggedOffDoode", @"javascript:" + jscript, true); lbl_Mask.StatusText = "You are termibated"; // sara Coner sead that upnl_Mask.Update();
i am using JQuery in my javascript,. but i bet you could do something like this “document.getElementById(‘logoff_btn’).click()” to click the button,.. but then you have to get your asp:button ClienID,.. like this “document.getElementById(‘” + logoff_btn.ClientID + “‘).click()” .. the DOM ready event is a Whole other story..