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

number display question

hello, i am confused about the following aspx page, when the Submit
button is clicked, the page will append a number to Label1, but i am
wondering why the first row displays twice, would u please tell me? how
can i solve this problem? thanks.

number: 0
number: 0 <--- why display twice
number: 1
number: 2
number: 3
number: 4

The aspx source:

<script language="C#" runat="server">

private int currentIndex;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["currentIndex"] = 0;
}

currentIndex = (int)ViewState["currentIndex"];

if (currentIndex < 5)
Label1.Text += "<br>number: " + currentIndex;

lblCurrentIndex.Text = "current index: " + currentIndex +
"<br>";
}

protected void Button1_Click(object sender, EventArgs e)
{
ViewState["currentIndex"] = currentIndex + 1;
}
</script>

<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Width="205px"></asp:Label><br />
<br />
<asp:Label ID="lblCurrentIndex" runat="server"></asp:Label><br
/>
<br />
<asp:Button ID="btnSubmit" runat="server"
OnClick="Button1_Click" Text="Submit" />

</div>
</form>
</body>
</html>

Aug 14 '06 #1
1 1175
PageLoad event fires before your Button1_Click event

"philip" wrote:
hello, i am confused about the following aspx page, when the Submit
button is clicked, the page will append a number to Label1, but i am
wondering why the first row displays twice, would u please tell me? how
can i solve this problem? thanks.

number: 0
number: 0 <--- why display twice
number: 1
number: 2
number: 3
number: 4

The aspx source:

<script language="C#" runat="server">

private int currentIndex;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["currentIndex"] = 0;
}

currentIndex = (int)ViewState["currentIndex"];

if (currentIndex < 5)
Label1.Text += "<br>number: " + currentIndex;

lblCurrentIndex.Text = "current index: " + currentIndex +
"<br>";
}

protected void Button1_Click(object sender, EventArgs e)
{
ViewState["currentIndex"] = currentIndex + 1;
}
</script>

<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
Width="205px"></asp:Label><br />
<br />
<asp:Label ID="lblCurrentIndex" runat="server"></asp:Label><br
/>
<br />
<asp:Button ID="btnSubmit" runat="server"
OnClick="Button1_Click" Text="Submit" />

</div>
</form>
</body>
</html>

Aug 14 '06 #2

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

Similar topics

1
by: dimension | last post by:
Hi, is it possible to display the Row number in the in the row selection column in a DataGridView (this is the "column" before your first column...when you click on it, it highlights the entire...
2
by: Irwinsp | last post by:
Hi All, I have a form with an auto number field displayed. The field looks great except when the user is entering a new record. The field then has the text "auto number" in it. Is there a...
3
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
4
by: the hotshot | last post by:
hello, this seems to be a hard question so far and noone has been able to help with this. is it possible to have access start an autonumber with a prefix according to the year when the data is...
4
by: rdemyan via AccessMonster.com | last post by:
I have the following SQL statement in code that is set to the RowSource of a combobox. The combobox has two columns. SELECT '(ALL)' As Site, '' As , 0 As SortFirst FROM GROUP BY SITE_COMPLEX...
4
by: c676228 | last post by:
Hi everyone, I need to write a insruance program which needs to collect multiple people information, The information for each person includes name, email, address, phone, dob etc. The DOB data...
3
by: gavm360 | last post by:
Hello, I'm making a data entry form that i would like to have display the operators name. So far i have a preceeding "Login" form in which the operator inputs his/her employee number into a...
2
by: Chris | last post by:
Hello, Quick and easy question, I hope..... Without using a text fieldtype, how can I get Access to store and display the number 12.1.2 or 1.3.9 ?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...

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.