Friday, February 17, 2012

view state gaffe

a common error in  O'Reilly's programming c# 3.0 - that viewstate is needed for retaing choices in drop downs- the following disproves that: 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="test_view_state._Default"  %>

<%@ Register src="property.ascx" tagname="property" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server"
            Text="Label"></asp:Label>
        <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
       
        <br />
        <asp:ListBox ID="ListBox1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:ListBox>
       
    </div>
    <uc1:property ID="property1" runat="server"  Text ="hhhhh"  />
    </form>
    </body>
</html>

namespace test_view_state
{
    [Author("george", version = 1.1)]
    public partial class _Default : System.Web.UI.Page
    {

        [Conditional("DEBUG")]
        private void callout()
        {
            this.EnableViewState = false;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

    }

    [System.AttributeUsage(System.AttributeTargets.Class |
                       System.AttributeTargets.Struct)]
    public class Author : System.Attribute
    {
        private string name;
        public double version;

        public Author(string name)
        {
            this.name = name;
            version = 1.0;
        }
    }

}

No comments:

Post a Comment