Thursday, August 26, 2010

How to postback a button to a diffrent page and invoke a relevent event

To postback a page to diffrent page and invoke a relevent event, we can use PostBackUrl property of the button contorl
Page1.aspx
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button 
            runat="server" 
            ID="btnSave" Text="Save" 
            PostBackUrl="~/Page2.aspx" 
            UseSubmitBehavior="false" />
    </div>
    </form>
</body>
</html>
Page2.aspx
<head id="Head1" runat="server">
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            string s = this.Request.Form["__EVENTTARGET"];
            if (s.Contains("btnSave")) this.Save();
        }
        protected void Save()
        {
 
        }
      </script>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...