I see many times people asking this question "How to open confirm box from codebehind or server side". Basically this situation comes when after performing some server side operation you need to show "Confirm" box to the client and if the user say OK then we need to fire the server side code again. In this blog I will show the same, actually in reality there is nothing like calling JS code from server side, a string is written in server side and in the RENDER method that string is thrown to the client so as to be parsed by JS engine at the client side. I have used the following three things to accomplish it:
ClientScript.GetPostBackEventReference
ClientScript.RegisterStartupScript
__doPostBack
ClientScript.GetPostBackEventReference: Returns a string that can be used in a client event to cause postback to the server.
ClientScript.RegisterStartupScript: Registers the startup script with the Page object.
_doPostBack: It is ASP.NET's way of doing javascript postbacks . The first argument is eventTarget, which is the control that is triggering the action. The second argument is event args means any additional information you might want to send with your postback.
Below is the sample code:
<%@ Page Language="C#" %>
No comments:
Post a Comment