我有一个 ASP.NET 页面,其中包含 10 个动态生成的 LinkButton 元素。当用户单击这些 LinkButton 元素之一时,我想在模式对话框中显示其文本。然后,用户可以通过在 TextBox 中输入值来更改文本。我的代码如下所示:
<asp:ScriptManager ID="theScriptManager" runat="server" />
<asp:UpdatePanel ID="myUpdatePanel" runat="server">
<ContentTemplate>
<asp:Table ID="myTable" runat="server" OnInit="myTable_Init" CellPadding="10" CellSpacing="10" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:LinkButton ID="testLinkButton" runat="server" />
<cc1:ModalPopupExtender ID="myPopupExtender" runat="server" TargetControlID="testLinkButton"
OkControlID="okButton" PopupControlID="myPanel" />
<asp:Panel ID="myPanel" runat="server" Style="display: none;">
<table border="1" cellpadding="0" cellspacing="0"><tr><td>
<table border="0" cellpadding="0" cellspacing="0" style="width: 300px;">
<tr><td colspan="2" style="background-color: Blue; font-weight: bold; color: White;">
Test
</td></tr>
<tr>
<td>You clicked <asp:TextBox ID="numTextBox" runat="server" MaxLength="3" />.</td>
<td align="right" style="padding-top: 5px; padding-bottom: 5px;">
<asp:Button ID="okButton" runat="server" Text="OK" OnClick="okButton_Click" />
</td>
</tr>
</table>
</td></tr></table>
</asp:Panel>
我的这个 ASP.NET 代码的代码隐藏如下所示:
private LinkButton selectedLinkButton = null;
protected void Page_Load(object sender, EventArgs e)
{}
protected void myTable_Init(object sender, EventArgs e)
{
TableRow row = new TableRow();
for (int i = 1; i < 11; i++)
{
LinkButton linkButton = new LinkButton();
linkButton.Text = i.ToString();
linkButton.Click += new EventHandler(linkButton_Click);
linkButton.CommandArgument = i.ToString();
AddLinkButtonToRow(linkButton, row);
}
myTable.Rows.Add(row);
}
protected void linkButton_Click(object sender, EventArgs e)
{
selectedLinkButton = (LinkButton)(sender);
numTextBox.Text = selectedLinkButton.CommandArgument;
myPopupExtender.Show();
}
protected void okButton_Click(object sender, EventArgs e)
{
if (selectedLinkButton != null)
{
selectedLinkButton.Text = numTextBox.Text.Trim();
}
}
private void AddLinkButtonToRow(LinkButton linkButton, TableRow row)
{
TableCell cell = new TableCell();
cell.Controls.Add(linkButton);
row.Cells.Add(cell);
}
我的问题是,我想减少回发的数量。为此,我决定使用 ASP.NET AJAX 工具包。不幸的是,一旦用户在对话框中单击“确定”,我在更新 LinkButton 文本方面没有任何成功。此外,我似乎仍在收到回发。我如何错误地使用它?
谢谢,