0
我有一個運行一些簡單代碼的.aspx文件。當我「提交」我的表單時,我在標籤上顯示了一些信息(lblCount),這取決於我的下拉列表中的代碼。當我多次提交時,它會重新創建標籤 - 我不明白爲什麼,除非我錯過某種財產。是否有一個屬性可以防止標籤重新繪製?當我從.aspx提交時重新繪製標籤
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label runat="server" id="lblError" />
<asp:DropDownList id="monthList" AutoPostBack = "True" runat = "server">
<asp:ListItem Selected = "True" Value = "January"> January </asp:ListItem>
<asp:ListItem Value = "February"> February </asp:ListItem>
<asp:ListItem Value = "March"> March </asp:ListItem>
<asp:ListItem Value = "April"> April </asp:ListItem>
<asp:ListItem Value = "May"> May </asp:ListItem>
<asp:ListItem Value = "June"> June </asp:ListItem>
<asp:ListItem Value = "July"> July </asp:ListItem>
<asp:ListItem Value = "August"> August </asp:ListItem>
<asp:ListItem Value = "September"> September </asp:ListItem>
<asp:ListItem Value = "October"> October </asp:ListItem>
<asp:ListItem Value = "November"> November </asp:ListItem>
<asp:ListItem Value = "December"> December </asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" id="lblCount" />
</div>
<asp:Button ID="submitButton" OnClick="MonthSelection" Text="Submit" runat="server" />
<div>
</div>
</form>
</body>
</html>
月份選擇:
protected void MonthSelection(object sender, EventArgs e)
{
dateLookup = monthList.SelectedItem.Value;
selectedMonth.Text = dateLookup.ToString();
switch (dateLookup)
{
case "January":
monthDate = 01;
break;
case "February":
monthDate = 02;
break;
case "March":
monthDate = 03;
break;
case "April":
monthDate = 04;
break;
case "May":
monthDate = 05;
break;
case "June":
monthDate = 06;
break;
case "July":
monthDate = 07;
break;
case "August":
monthDate = 08;
break;
case "September":
monthDate = 09;
break;
case "October":
monthDate = 10;
break;
case "November":
monthDate = 11;
break;
case "December":
monthDate = 12;
break;
}
try
{
string sql = "SELECT COUNT(*) FROM members_ WHERE DATEPART(month, DateUnsub_) = " + monthDate + " AND DATEPART(year, DateUnsub_) = 2011 AND DATEDIFF(day, DateJoined_, DateUnsub_) <= 30";
String[][] results = lm.SqlSelect(sql);
if (results != null)
{
for (int i = 0; i < results.Length; i++)
{
if (results[i] != null)
{
for (int j = 0; j < results[i].Length; j++)
{
if (results[i][j] != null)
{
if (results[i][j].Length > 5)
lblCount.Text += results[i][j];
else
lblCount.Text += results[i][j];
}
}
}
}
}
}
catch (SoapHeaderException ex)
{
lblError.Text = ex.Message;
}
}
我們也需要看到MonthSelection函數。 – Bill
好的 - 你去了! –
我所有的其他標籤都正常工作。只是一個標籤不斷重印自己。 –