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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...