Wrox Programmer Forums
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 2nd, 2006, 05:35 AM
Registered User
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Strange ListBox problem

I am new to ASP.NET programming. I built a very simple ASP.NET application with C# using visual studio 2003. There is a ListBox in there. It works ok when I run it from visual studio. After I deploy the application to the server, All the items that I had added to the ListBox are always cleared for each postback event. The state view doesn't work any more. by the way, enablestateview has been set to true for the ListBox and Page_Load function is empty. The items in the ListBox are added by buttom click.

private void Add_Click(object sender, System.EventArgs e)

Is there anyone has a clue on this? Thank you very much in advance.

Old August 2nd, 2006, 06:29 AM
Authorized User
Join Date: Oct 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts

If your pageload is empty and Listbox's enable viewstate is true then your list box content will not clear after each post back. can you give your full code so that i can find out if the problem is some where else.

Software professional from Bangalore,INDIA
Old August 2nd, 2006, 06:52 AM
Registered User
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

Thank you so much for your reply!

This is the WebForm1.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication2
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Button Add;
    protected System.Web.UI.WebControls.Button select;
    protected System.Web.UI.WebControls.ListBox ListBox1;

    private void Page_Load(object sender, System.EventArgs e)
        // Put user code to initialize the page here

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    this.Add.Click += new System.EventHandler(this.Add_Click);
        this.select.Click += new System.EventHandler(this.select_Click);
    this.Load += new System.EventHandler(this.Page_Load);


    private void Add_Click(object sender, System.EventArgs e)

    private void select_Click(object sender, System.EventArgs e)





This is WebForm1.aspx

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" smartNavigation="True" enableViewStateMac="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="C#" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 280px; POSITION: absolute; TOP: 152px"
            <asp:Button id="Add" style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 248px" runat="server"
            <asp:Button id="select" style="Z-INDEX: 103; LEFT: 200px; POSITION: absolute; TOP: 304px" runat="server"
            <asp:ListBox id="ListBox1" style="Z-INDEX: 104; LEFT: 352px; POSITION: absolute; TOP: 216px"
                runat="server" Width="240px" Height="192px"></asp:ListBox></form>

This is the Web.config

<?xml version="1.0" encoding="utf-8" ?>


          Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to
          false will improve runtime performance of this application.
          Set compilation debug="true" to insert debugging symbols (.pdb information)
          into the compiled page. Because this creates a larger file that executes
          more slowly, you should set this value to true only when debugging and to
          false at all other times. For more information, refer to the documentation about
          debugging ASP.NET files.

          Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
          Add <error> tags for each of the errors you want to handle.

          "On" Always display custom (friendly) messages.
          "Off" Always display detailed ASP.NET error information.
          "RemoteOnly" Display custom (friendly) messages only to users not running
           on the local Web server. This setting is recommended for security purposes, so
           that you do not display application detail information to remote clients.

          This section sets the authentication policies of the application. Possible modes are "Windows",
          "Forms", "Passport" and "None"

          "None" No authentication is performed.
          "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
           its settings for the application. Anonymous access must be disabled in IIS.
          "Forms" You provide a custom form (Web page) for users to enter their credentials, and then
           you authenticate them in your application. A user credential token is stored in a cookie.
          "Passport" Authentication is performed via a centralized authentication service provided
           by Microsoft that offers a single logon and core profile services for member sites.
    <authentication mode="Windows" />

          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
          (unauthenticated) users.

        <allow users="*" />
            <!-- <allow users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>

          Application-level tracing enables trace log output for every page within an application.
          Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
          trace information will be displayed at the bottom of each page. Otherwise, you can view the
          application trace log by browsing the "trace.axd" page from your web application

          By default ASP.NET uses cookies to identify which requests belong to a particular session.
          If cookies are not available, a session can be tracked by adding a session identifier to the URL.
          To disable cookies, set sessionState cookieless="true".
            sqlConnectionString="data source=;Trusted_Connection=yes"

          This section sets the globalization settings of the application.



select_Click should display the selected item in TextBox1, but it always do nothing. The strange thing is it works ok if I run it from visual studio (with localhost). Can it be some setting with .net framework or asp services? I am totally new this issue.

Thanks again.

Old August 2nd, 2006, 08:30 AM
Registered User
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts

Here is some more observation of the problem.
when I deploy the application. I add a virtual Directory to an existing web site and copy my file there. it can't work correctly. But if I add a new web site to the server for the application. It works ok. Maybe it is the setting of the existing web site. Any ideas?


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange IE problem sully7 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 September 19th, 2008 08:44 AM
Strange problem... F3553 C++ Programming 1 October 25th, 2007 03:56 PM
Strange ListBox Problem mirandaym ASP.NET 2.0 Basics 1 August 2nd, 2006 05:00 AM
kind of Really strange problem kalchev ASP.NET 2.0 Basics 1 March 22nd, 2006 03:32 PM
very strange problem! please help! raybristol ASP.NET 1.0 and 1.1 Basics 8 December 15th, 2005 06:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.