Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 November 28th, 2003, 09:38 PM
Authorized User
 
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default viewstate issue ?

Hi all,
i have a problem which i suspect to be related to the viewstate property.
Im using code-behind to bind a datareader to an asp:dropDownList control.
for the first few times it all seems ok but after that im getting an empty dropdownlist control.
even when i close my sql server i still get the same with NO error regarding the closed sql Server.
"view source" for the resulted page shows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form name="Form1" method="post" action="main.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwxNTYyMTgwMDUyOzs+GmrvyRI2ZAfwgsocIcvSHNx RvRo=" />

            <select name="packageTypes" id="packageTypes">

</select>
        </form>
    </body>
</HTML>

I guess it something pretty simple.
any1 has any idea ?

Thanks in advance






Yuval Kronenfeld
Web Developer
__________________
Yuval Kronenfeld
Israel
 
Old November 28th, 2003, 11:15 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are you binding to the drop down every time you load the page? Usually you want to only databind the DDL on the first page load (based on a check of IsPostback). This could be causing a problem, but it doesn't seem like it would result in what you are saying. If you bind the ddl every time, you can end up with events not firing but usually, it doesn't result in missing data.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 28th, 2003, 11:29 PM
Authorized User
 
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,
I didnt make the ispostback check .
But i added it now and after trying to run again it still act the same and doesnt care if the sqlServer is on or not.

bellow you will find the webform code and later the code-behind(i use a class library - DataHandler - as Data Access Layer)

<%@ Page language="c#" Codebehind="main.aspx.cs" AutoEventWireup="false" Inherits="WIS.main" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server" >
            <asp:DropDownList ID="packageTypes" runat=server/>
        </form>
    </body>
</HTML>

'------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DataHandler ;

namespace WIS
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class main : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DropDownList packageTypes;

        private void Page_Load(object sender, System.EventArgs e)
        {
            if(!IsPostBack)
            {
                DataHandler.DataHandler DataHandler = new DataHandler.DataHandler();
                DataHandler.OpenConn();
                packageTypes.DataSource = DataHandler.getDataReader("SPPackageTypes");
                packageTypes.DataTextField = "type";
                packageTypes.DataValueField = "ID";
                packageTypes.DataBind();
            }
        }

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

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion
    }
}



Yuval Kronenfeld
Web Developer
 
Old November 28th, 2003, 11:59 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If it doesn't break when you change the way it's getting data, then I would say there might be something wrong with the way you get the data. What you have in your page codebehind looks just fine.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 29th, 2003, 07:13 AM
Authorized User
 
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

unless i miss something here - getting the data seems to be ok - it worked the first few times...but after that - nothing
 
Old November 29th, 2003, 11:33 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If the DDL shows up right the first time, but doesn't after that, and you are only populating the data the first time, then perhaps something else is causing the data to change. Do you have any other events in the page that are manipulating that DDL's data? Otherwise, I don't know what to tell you.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 30th, 2003, 04:18 AM
Authorized User
 
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have no other events.
but i agree with you - it seems like something else is wrong.
strange.
10x for the help anyway.I appriciate it.
Yuval.





Similar Threads
Thread Thread Starter Forum Replies Last Post
viewstate error balesh.mind ASP.NET 2.0 Professional 1 August 31st, 2007 08:51 PM
ViewState Wervis C# 1 December 3rd, 2005 11:35 AM
Viewstate Wervis BOOK: ASP.NET Website Programming Problem-Design-Solution 0 November 30th, 2005 09:42 AM
ViewState abdul_owiusa General .NET 0 October 18th, 2005 04:37 PM
ViewState burhan ASP.NET 1.0 and 1.1 Basics 4 June 6th, 2004 04:25 AM





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