473,395 Members | 1,670 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,395 software developers and data experts.

Problem with dynamic change of control value

Hi,

I have very simple Page_Load code in some code-behind class in ASP.NET (v.
1.1):

private void Page_Load(object sender, System.EventArgs e)
{
if ( IsPostBack )
DropDownList1.SelectedIndex = 5;
else
{
FillDropDownList( DropDownList1 ); // some method to fill
values in list
DropDownList1.SelectedIndex = 0;
}
}

Everything is fine with selection first time Web page is loaded -- first
item in the dropdown list is selected. Problem is that selection does not
change to 5 when the page is loaded next time in response to some client
action -- it is always 0 in client side when page is reloaded. Same problem
goes for other controls in the form -- neither labels nor text boxes texts
can be changed dynamicaly in Page_Load. Any help please?

Airshow
Nov 19 '05 #1
1 1173
Airshow:
Works fine for me. Are you sure there are 6 items in the dropdownlist? if
you have 5 or less items, doing selectedindex=5 won't work :)

Also, you say "next time in response to some client action" what's the
client action? Are they simply hitting "f5" to reload the page or are they
hitting an control which causes postback?

if you take this basic example:
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" Runat="server" />
<asp:Button id="btn" Runat="server" />
</form>

<script runat="server">
private void Page_Load(object sender, System.EventArgs e) {
if ( IsPostBack )
DropDownList1.SelectedIndex = 5;
else {
FillDropDownList( DropDownList1 ); // some method to fill
DropDownList1.SelectedIndex = 0;
}
}
private void FillDropDownList(DropDownList ddl) {
ddl.Items.Add("1");
ddl.Items.Add("2");
ddl.Items.Add("3");
ddl.Items.Add("4");
ddl.Items.Add("5");
ddl.Items.Add("6");
}
</script>

it works.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Airshow" <ai*****@hotmail.com> wrote in message
news:em****************@TK2MSFTNGP11.phx.gbl...
Hi,

I have very simple Page_Load code in some code-behind class in ASP.NET (v.
1.1):

private void Page_Load(object sender, System.EventArgs e)
{
if ( IsPostBack )
DropDownList1.SelectedIndex = 5;
else
{
FillDropDownList( DropDownList1 ); // some method to fill values in list
DropDownList1.SelectedIndex = 0;
}
}

Everything is fine with selection first time Web page is loaded -- first
item in the dropdown list is selected. Problem is that selection does not
change to 5 when the page is loaded next time in response to some client
action -- it is always 0 in client side when page is reloaded. Same problem goes for other controls in the form -- neither labels nor text boxes texts
can be changed dynamicaly in Page_Load. Any help please?

Airshow

Nov 19 '05 #2

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

Similar topics

0
by: Kalyani | last post by:
Hi, I have a page with one DropDownList and a Placeholder.This placeholder wil contain either a textbox or a DropDownList depending upon the value in previous DropDownList. Also there is a Submit...
4
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build...
1
by: pbb | last post by:
I'm creating a set of dynamic controls on a webpage by calling my BuildControls sub in the Page_Init sub. I recreate the controls by calling the BuildControls sub in the LoadViewState override...
1
by: Kalyani | last post by:
Hi, I have a page with one DropDownList and a Placeholder.This placeholder wil contain either a textbox or a DropDownList depending upon the value in previous DropDownList. Also there is a Submit...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.