Expose the control through a page property : Page Class « Page Lifecycle « ASP.NET Tutorial






<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    public string SearchString
    {
        get { return txtSearch.Text; }
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Button Search Typed</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblSearch"
        Text="Search:"
        Runat="server" />
    <asp:TextBox
        id="txtSearch"
        Runat="server" />
    <asp:Button
        id="btnSearch"
        Text="Go!"
        PostBackUrl="NextPage.aspx"
        Runat="server" />
    </div>
    </form>
</body>
</html>


File: NextPage.aspx


<%@ Page Language="C#" %>
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void Page_Load()
    {
        if (Page.PreviousPage != null)
        {
            lblSearch.Text = String.Format("Search For: {0}", PreviousPage.SearchString);
        }
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Button Search Results Typed</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblSearch"
        Runat="server" />

    </div>
    </form>
</body>
</html>








5.1.Page Class
5.1.1.Fundamental properties in The Page Class
5.1.2.aspx page inherits from a 'Page' class (C#)
5.1.3.aspx page inherits from a 'Page' class (vb.net)
5.1.4.Expose the control through a page property
5.1.5.Page.ErrorPage
5.1.6.Page.HasControls
5.1.7.Is page valid
5.1.8.Page.ResolveUrl