Home All Groups Group Topic Archive Search About
Author
10 Jun 2005 10:54 AM
Ron Wallegie
Hi,

I developed a website using c#. I have a dropdownlist wich is filled with
database values. When i click on a button on the same page all values are
lost in the dropdownlist.
The most common answer is to populate the ddl in "if !is postback" which i
did. When i debug it seems that before the postback all values are lost.

When i tried to do the same on my local machine (localhost) everything works
fine.

Can someone please help

regards
Ron

Author
10 Jun 2005 12:12 PM
Teemu Keiski
Hi,

can you show the code you have? And you don't have ViewState disabled?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke



Show quoteHide quote
"Ron Wallegie" <walle***@hotmail.com> wrote in message
news:e$POstabFHA.2520@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I developed a website using c#. I have a dropdownlist wich is filled with
> database values. When i click on a button on the same page all values are
> lost in the dropdownlist.
> The most common answer is to populate the ddl in "if !is postback" which i
> did. When i debug it seems that before the postback all values are lost.
>
> When i tried to do the same on my local machine (localhost) everything
> works
> fine.
>
> Can someone please help
>
> regards
> Ron
>
>
Author
10 Jun 2005 12:29 PM
Ron Wallegie
Thank for your reply!

I created an hashtable, which i use to fill my dropdownlist.
On my form i've got a dropdownlist, 1 button and a textfield.
When i click on the button, all values in my form (textbox and dropdownlist)
are lost!

Keep in mind that everything worked fine on my local machine and viewstate
is enabled.

Your help is much appreciated

Regards,
Ron

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 WebApplication1
{
            /// <summary>
            /// Summary description for WebForm2.
            /// </summary>
            public class WebForm2 : System.Web.UI.Page
            {
                        protected System.Web.UI.WebControls.TextBox
TextBox1;
                        protected System.Web.UI.WebControls.Button Button1;
                        protected System.Web.UI.WebControls.DropDownList
DropDownList1;

                        private void Page_Load(object sender,
System.EventArgs e)
                        {
                                    if (!IsPostBack)
                                    {
                                                Hashtable myHash = new
Hashtable();
                                                myHash.Add("1", "One");
                                                myHash.Add("2", "Two");
                                                myHash.Add("3", "Three");
                                                myHash.Add("4", "Four");

                                                foreach (DictionaryEntry
myDE  in myHash)
                                                {
                                                            ListItem newLi =
new ListItem();
                                                            newLi.Text =
myDE.Value.ToString();
                                                            newLi.Value =
myDE.Key.ToString();
                                                            DropDownList1.Items.Add(newLi);
                                                }
                                    }
                        }

                        #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()
                        {
                                    this.Button1.Click += new
System.EventHandler(this.Button1_Click);
                                    this.Load += new
System.EventHandler(this.Page_Load);

                        }
                        #endregion

                        private void Button1_Click(object sender,
System.EventArgs e)
                        {
                                    TextBox1.Text =
DropDownList1.SelectedValue;
                        }
            }
}
Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:ehfkuWbbFHA.3204@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> can you show the code you have? And you don't have ViewState disabled?
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>
>
> "Ron Wallegie" <walle***@hotmail.com> wrote in message
> news:e$POstabFHA.2520@TK2MSFTNGP09.phx.gbl...
>> Hi,
>>
>> I developed a website using c#. I have a dropdownlist wich is filled with
>> database values. When i click on a button on the same page all values are
>> lost in the dropdownlist.
>> The most common answer is to populate the ddl in "if !is postback" which
>> i
>> did. When i debug it seems that before the postback all values are lost.
>>
>> When i tried to do the same on my local machine (localhost) everything
>> works
>> fine.
>>
>> Can someone please help
>>
>> regards
>> Ron
>>
>>
>
>
Author
10 Jun 2005 1:04 PM
Teemu Keiski
Can you show also the aspx part? Especially do you have <form runat="server"
method="post"> (especially the method and runat here)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke



Show quoteHide quote
"Ron Wallegie" <walle***@hotmail.com> wrote in message
news:OoO4wibbFHA.2520@TK2MSFTNGP09.phx.gbl...
> Thank for your reply!
>
> I created an hashtable, which i use to fill my dropdownlist.
> On my form i've got a dropdownlist, 1 button and a textfield.
> When i click on the button, all values in my form (textbox and
> dropdownlist) are lost!
>
> Keep in mind that everything worked fine on my local machine and viewstate
> is enabled.
>
> Your help is much appreciated
>
> Regards,
> Ron
>
> 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 WebApplication1
> {
>            /// <summary>
>            /// Summary description for WebForm2.
>            /// </summary>
>            public class WebForm2 : System.Web.UI.Page
>            {
>                        protected System.Web.UI.WebControls.TextBox
> TextBox1;
>                        protected System.Web.UI.WebControls.Button Button1;
>                        protected System.Web.UI.WebControls.DropDownList
> DropDownList1;
>
>                        private void Page_Load(object sender,
> System.EventArgs e)
>                        {
>                                    if (!IsPostBack)
>                                    {
>                                                Hashtable myHash = new
> Hashtable();
>                                                myHash.Add("1", "One");
>                                                myHash.Add("2", "Two");
>                                                myHash.Add("3", "Three");
>                                                myHash.Add("4", "Four");
>
>                                                foreach (DictionaryEntry
> myDE  in myHash)
>                                                {
>                                                            ListItem newLi
> = new ListItem();
>                                                            newLi.Text =
> myDE.Value.ToString();
>                                                            newLi.Value =
> myDE.Key.ToString();
>
> DropDownList1.Items.Add(newLi);
>                                                }
>                                    }
>                        }
>
>                        #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()
>                        {
>                                    this.Button1.Click += new
> System.EventHandler(this.Button1_Click);
>                                    this.Load += new
> System.EventHandler(this.Page_Load);
>
>                        }
>                        #endregion
>
>                        private void Button1_Click(object sender,
> System.EventArgs e)
>                        {
>                                    TextBox1.Text =
> DropDownList1.SelectedValue;
>                        }
>            }
> }
> "Teemu Keiski" <jot***@aspalliance.com> wrote in message
> news:ehfkuWbbFHA.3204@TK2MSFTNGP12.phx.gbl...
>> Hi,
>>
>> can you show the code you have? And you don't have ViewState disabled?
>>
>> --
>> Teemu Keiski
>> ASP.NET MVP, AspInsider
>> Finland, EU
>> http://blogs.aspadvice.com/joteke
>>
>>
>>
>> "Ron Wallegie" <walle***@hotmail.com> wrote in message
>> news:e$POstabFHA.2520@TK2MSFTNGP09.phx.gbl...
>>> Hi,
>>>
>>> I developed a website using c#. I have a dropdownlist wich is filled
>>> with
>>> database values. When i click on a button on the same page all values
>>> are
>>> lost in the dropdownlist.
>>> The most common answer is to populate the ddl in "if !is postback" which
>>> i
>>> did. When i debug it seems that before the postback all values are lost.
>>>
>>> When i tried to do the same on my local machine (localhost) everything
>>> works
>>> fine.
>>>
>>> Can someone please help
>>>
>>> regards
>>> Ron
>>>
>>>
>>
>>
>
>
Author
10 Jun 2005 1:25 PM
Mark
Teemu,

Here's the complete code you asked for:

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false"
Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
  <title>WebForm2</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="DropDownList1" style="Z-INDEX: 101; LEFT: 32px;
POSITION: absolute; TOP: 40px"
    runat="server"></asp:DropDownList>
   <asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 192px; POSITION:
absolute; TOP: 40px" runat="server"
    Width="232px" Height="112px"></asp:TextBox>
   <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 112px; POSITION:
absolute; TOP: 40px" runat="server"
    Text="Button"></asp:Button>
  </form>
</body>
</HTML>

Looks normal to me...

Regards,
Mark

Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:%23yVn1zbbFHA.2896@TK2MSFTNGP10.phx.gbl...
> Can you show also the aspx part? Especially do you have <form
> runat="server" method="post"> (especially the method and runat here)
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>
>
> "Ron Wallegie" <walle***@hotmail.com> wrote in message
> news:OoO4wibbFHA.2520@TK2MSFTNGP09.phx.gbl...
>> Thank for your reply!
>>
>> I created an hashtable, which i use to fill my dropdownlist.
>> On my form i've got a dropdownlist, 1 button and a textfield.
>> When i click on the button, all values in my form (textbox and
>> dropdownlist) are lost!
>>
>> Keep in mind that everything worked fine on my local machine and
>> viewstate is enabled.
>>
>> Your help is much appreciated
>>
>> Regards,
>> Ron
>>
>> 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 WebApplication1
>> {
>>            /// <summary>
>>            /// Summary description for WebForm2.
>>            /// </summary>
>>            public class WebForm2 : System.Web.UI.Page
>>            {
>>                        protected System.Web.UI.WebControls.TextBox
>> TextBox1;
>>                        protected System.Web.UI.WebControls.Button
>> Button1;
>>                        protected System.Web.UI.WebControls.DropDownList
>> DropDownList1;
>>
>>                        private void Page_Load(object sender,
>> System.EventArgs e)
>>                        {
>>                                    if (!IsPostBack)
>>                                    {
>>                                                Hashtable myHash = new
>> Hashtable();
>>                                                myHash.Add("1", "One");
>>                                                myHash.Add("2", "Two");
>>                                                myHash.Add("3", "Three");
>>                                                myHash.Add("4", "Four");
>>
>>                                                foreach (DictionaryEntry
>> myDE  in myHash)
>>                                                {
>>                                                            ListItem newLi
>> = new ListItem();
>>                                                            newLi.Text =
>> myDE.Value.ToString();
>>                                                            newLi.Value =
>> myDE.Key.ToString();
>>
>> DropDownList1.Items.Add(newLi);
>>                                                }
>>                                    }
>>                        }
>>
>>                        #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()
>>                        {
>>                                    this.Button1.Click += new
>> System.EventHandler(this.Button1_Click);
>>                                    this.Load += new
>> System.EventHandler(this.Page_Load);
>>
>>                        }
>>                        #endregion
>>
>>                        private void Button1_Click(object sender,
>> System.EventArgs e)
>>                        {
>>                                    TextBox1.Text =
>> DropDownList1.SelectedValue;
>>                        }
>>            }
>> }
>> "Teemu Keiski" <jot***@aspalliance.com> wrote in message
>> news:ehfkuWbbFHA.3204@TK2MSFTNGP12.phx.gbl...
>>> Hi,
>>>
>>> can you show the code you have? And you don't have ViewState disabled?
>>>
>>> --
>>> Teemu Keiski
>>> ASP.NET MVP, AspInsider
>>> Finland, EU
>>> http://blogs.aspadvice.com/joteke
>>>
>>>
>>>
>>> "Ron Wallegie" <walle***@hotmail.com> wrote in message
>>> news:e$POstabFHA.2520@TK2MSFTNGP09.phx.gbl...
>>>> Hi,
>>>>
>>>> I developed a website using c#. I have a dropdownlist wich is filled
>>>> with
>>>> database values. When i click on a button on the same page all values
>>>> are
>>>> lost in the dropdownlist.
>>>> The most common answer is to populate the ddl in "if !is postback"
>>>> which i
>>>> did. When i debug it seems that before the postback all values are
>>>> lost.
>>>>
>>>> When i tried to do the same on my local machine (localhost) everything
>>>> works
>>>> fine.
>>>>
>>>> Can someone please help
>>>>
>>>> regards
>>>> Ron
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Jun 2005 2:06 PM
Ron Wallegie
Perhaps you can find the problem.
Thx in advance
Regards,

Ron

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false"
Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
  <title>WebForm2</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="DropDownList1" style="Z-INDEX: 101; LEFT: 32px;
POSITION: absolute; TOP: 40px"
    runat="server"></asp:DropDownList>
   <asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 192px; POSITION:
absolute; TOP: 40px" runat="server"
    Width="232px" Height="112px"></asp:TextBox>
   <asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 112px; POSITION:
absolute; TOP: 40px" runat="server"
    Text="Button"></asp:Button>
  </form>
</body>
</HTML>


Show quoteHide quote
"Teemu Keiski" <jot***@aspalliance.com> wrote in message
news:%23yVn1zbbFHA.2896@TK2MSFTNGP10.phx.gbl...
> Can you show also the aspx part? Especially do you have <form
> runat="server" method="post"> (especially the method and runat here)
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
>
>
>
> "Ron Wallegie" <walle***@hotmail.com> wrote in message
> news:OoO4wibbFHA.2520@TK2MSFTNGP09.phx.gbl...
>> Thank for your reply!
>>
>> I created an hashtable, which i use to fill my dropdownlist.
>> On my form i've got a dropdownlist, 1 button and a textfield.
>> When i click on the button, all values in my form (textbox and
>> dropdownlist) are lost!
>>
>> Keep in mind that everything worked fine on my local machine and
>> viewstate is enabled.
>>
>> Your help is much appreciated
>>
>> Regards,
>> Ron
>>
>> 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 WebApplication1
>> {
>>            /// <summary>
>>            /// Summary description for WebForm2.
>>            /// </summary>
>>            public class WebForm2 : System.Web.UI.Page
>>            {
>>                        protected System.Web.UI.WebControls.TextBox
>> TextBox1;
>>                        protected System.Web.UI.WebControls.Button
>> Button1;
>>                        protected System.Web.UI.WebControls.DropDownList
>> DropDownList1;
>>
>>                        private void Page_Load(object sender,
>> System.EventArgs e)
>>                        {
>>                                    if (!IsPostBack)
>>                                    {
>>                                                Hashtable myHash = new
>> Hashtable();
>>                                                myHash.Add("1", "One");
>>                                                myHash.Add("2", "Two");
>>                                                myHash.Add("3", "Three");
>>                                                myHash.Add("4", "Four");
>>
>>                                                foreach (DictionaryEntry
>> myDE  in myHash)
>>                                                {
>>                                                            ListItem newLi
>> = new ListItem();
>>                                                            newLi.Text =
>> myDE.Value.ToString();
>>                                                            newLi.Value =
>> myDE.Key.ToString();
>>
>> DropDownList1.Items.Add(newLi);
>>                                                }
>>                                    }
>>                        }
>>
>>                        #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()
>>                        {
>>                                    this.Button1.Click += new
>> System.EventHandler(this.Button1_Click);
>>                                    this.Load += new
>> System.EventHandler(this.Page_Load);
>>
>>                        }
>>                        #endregion
>>
>>                        private void Button1_Click(object sender,
>> System.EventArgs e)
>>                        {
>>                                    TextBox1.Text =
>> DropDownList1.SelectedValue;
>>                        }
>>            }
>> }
>> "Teemu Keiski" <jot***@aspalliance.com> wrote in message
>> news:ehfkuWbbFHA.3204@TK2MSFTNGP12.phx.gbl...
>>> Hi,
>>>
>>> can you show the code you have? And you don't have ViewState disabled?
>>>
>>> --
>>> Teemu Keiski
>>> ASP.NET MVP, AspInsider
>>> Finland, EU
>>> http://blogs.aspadvice.com/joteke
>>>
>>>
>>>
>>> "Ron Wallegie" <walle***@hotmail.com> wrote in message
>>> news:e$POstabFHA.2520@TK2MSFTNGP09.phx.gbl...
>>>> Hi,
>>>>
>>>> I developed a website using c#. I have a dropdownlist wich is filled
>>>> with
>>>> database values. When i click on a button on the same page all values
>>>> are
>>>> lost in the dropdownlist.
>>>> The most common answer is to populate the ddl in "if !is postback"
>>>> which i
>>>> did. When i debug it seems that before the postback all values are
>>>> lost.
>>>>
>>>> When i tried to do the same on my local machine (localhost) everything
>>>> works
>>>> fine.
>>>>
>>>> Can someone please help
>>>>
>>>> regards
>>>> Ron
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
10 Jun 2005 4:17 PM
Teemu Keiski
I can't see anything wrong with this one either. When you run the Page for
the first time on the server (e.g just load), check HTML source, is there
anything special in it? And then click the Button and check the source
again. Is the only difference then that there are no <option> elements in
the DropDownList?

Is it sure that that there doesn't happen something else in the Button
click, which might effect this behaviour?

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Author
10 Jun 2005 12:37 PM
Aaron Corcoran
Ron,

The odd thing is that it sounds like you have everything set up
properly if it is providing you the desired result on your local
machine.  However, you say that the problem arises once it is moved to
another machine (i.e., the development or production environment)?  I
have experienced such happenings, only to discover that something might
have been corrupted within the .NET Framework, or at least that is my
take on it.

If you want to try something, that won't take too much time and will
also knock out one possible cause, try reinstalling the framework using
the command prompt:

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322>aspnet_regiis -i

Again, I am not sure if this will solve the issue you may be having,
but it sounds like it may be some type of issue on the other machine
and not with the code.

I hope this helps,
Aaron
Author
10 Jun 2005 1:34 PM
Ron Wallegie
Did not work. But thx for your help. It seems this isn't a small problem.

with kind regards,

Ron

Show quoteHide quote
"Aaron Corcoran" <acorco***@lasers.state.la.us> wrote in message
news:1118407073.830024.229180@o13g2000cwo.googlegroups.com...
> Ron,
>
> The odd thing is that it sounds like you have everything set up
> properly if it is providing you the desired result on your local
> machine.  However, you say that the problem arises once it is moved to
> another machine (i.e., the development or production environment)?  I
> have experienced such happenings, only to discover that something might
> have been corrupted within the .NET Framework, or at least that is my
> take on it.
>
> If you want to try something, that won't take too much time and will
> also knock out one possible cause, try reinstalling the framework using
> the command prompt:
>
> C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322>aspnet_regiis -i
>
> Again, I am not sure if this will solve the issue you may be having,
> but it sounds like it may be some type of issue on the other machine
> and not with the code.
>
> I hope this helps,
> Aaron
>