views:

20

answers:

2

Is SearchString acting as property of Page class? Here is code,

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<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="ButtonSearchResultsTyped.aspx"
        Runat="server" />
    </div>
    </form>
</body>
</html>
+1  A: 

It's a property of the class generated for your ASPX file, which inherits from System.Web.UI.Page. It's not added to that class itself, of course.

Mehrdad Afshari
+1  A: 

It is a property of your page class. This is not the page class. Your class inherits from the main page class.

Also, you need to be careful how you use thist kind of thing. Remember, ASP.Net pages are stateless, just like with other platforms. That means every time you do a postback, including just to handle simple server events like button clicks, you are working with a new instance of the class. Any previous SearchString value was lost.

Joel Coehoorn