我有一個包含10個動態生成的LinkButton元素的ASP.NET頁面。當用戶點擊其中一個LinkButton元素時,我想在模態對話框中顯示其文本。用戶可以通過在TextBox中輸入值來更改文本。我給這家代碼如下所示:ASP.NET - 使用ModalPopupExtender阻止頁面刷新
<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文本。另外,我似乎仍然收到回傳。我如何正確使用它?
謝謝