P
philip
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>
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>