473,427 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

Page loses values

I developed a webesite 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
Nov 17 '05 #1
3 1569
hi

post some code, especially where you define the dropdown in the aspx file
and where you fill it and the load method

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ron Wallegie" <wa******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I developed a webesite 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

Nov 17 '05 #2
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;
}
}
}

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
hi

post some code, especially where you define the dropdown in the aspx file
and where you fill it and the load method

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ron Wallegie" <wa******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I developed a webesite 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


Nov 17 '05 #3
Thx for you reply.
This is probarly what you wanted.
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>

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
hi

post some code, especially where you define the dropdown in the aspx file
and where you fill it and the load method

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ron Wallegie" <wa******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I developed a webesite 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


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: quique | last post by:
Hi I,m gonna explain my scenario problem: I've got an user control that i want to cache in diferent pages attending to the value of a parameter x, to make t possible i put the next directive in...
5
by: Robert Phillips | last post by:
I have a Panel control containing a few TextBox controls. The Panel is originally enabled, I enter data into the TextBox controls. When I submit, the Panel is disabled during the PostBack and the...
1
by: Raheel Hussain | last post by:
hi, can any body tell me why the variable loses its value, i m actually declaring a variable which is public, and assigning a values in Function1 and reading the values in Function2 following...
4
by: Mark Broadbent | last post by:
This one has got me absolutely stumped. At work I have created a simple web form that gets data from a sql backend and puts this to a dataset. I have an edit button that when clicked will set...
1
by: Janaka | last post by:
Help! I have two ListBox controls on my web form. The first one gets populated on entry with values from the DB. I then use JavaScript to copy options from this ListBox to my second one. (I...
1
by: Tom wilson | last post by:
Yes, I'm sorry, it's me again. :) Yesterday I went through hell trying to figure out why my aspx pages wouldn't maintain state. I had a simple example I (we) eventually got to work. What...
7
by: jvaradarajan | last post by:
I've an ASP page which generates 4 kinds of reports based on a selection from a dropdownlist. There is a dropdownlist, datagrid and a generate report button in the page. The page works fine in IE....
1
by: stimul8d | last post by:
okay; ASP. I have i listbox inside a user control which is dynamically created on page_init. I check for postback and only populate the datasource if it's false. regardless, i do this ...
8
LacrosseB0ss
by: LacrosseB0ss | last post by:
Hey folks; I have PHP session variables that are having some troubles. I posted in a few other forums but couldn't really find one dedicated to my specific issue. I am using a few session variables...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.