我在代码隐藏中有以下代码块,它们在每行的最后一个单元格中动态创建一个带有Edit按钮的表:
Table table = null;
string BranchName = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
TableRow tr;
if (BranchName != dt.Rows[i]["Category"].ToString())
{
BranchName = dt.Rows[i]["Category"].ToString();
// setup pane
pane = new AccordionPane();
// add pane to accordion
acrDynamic.Panes.Add(pane);
// pane content
lbTitle = new Label();
pane.ID = "Pane_" + BranchName;
lbTitle.Text = BranchName;
pane.HeaderContainer.Controls.Add(lbTitle);
// pane container will have the table
table = new Table();
table.CssClass = "hoverTable";
pane.ContentContainer.Controls.Add(table);
// top row
tr = new TableRow();
// cells
TableHeaderCell th = new TableHeaderCell();
th.CssClass = "hoverHeader";
th.Width = 440;
th.Text = "Provision";
// set other properties
tr.Controls.Add(th);
// create next control
th = new TableHeaderCell();
th.CssClass = "hoverHeader";
th.Width = 120;
th.Text = "Mark for Review";
// set other properties
tr.Controls.Add(th);
// etc for other columns
table.Controls.Add(tr);
// create next control
th = new TableHeaderCell();
th.CssClass = "hoverHeader";
th.Width = 120;
th.Text = "Issue Type";
// set other properties
tr.Controls.Add(th);
// etc for other columns
table.Controls.Add(tr);
// create next control
th = new TableHeaderCell();
th.CssClass = "hoverHeader";
th.Width = 120;
th.Text = "Resolution";
// set other properties
tr.Controls.Add(th);
// etc for other columns
table.Controls.Add(tr);
// create next control
th = new TableHeaderCell();
th.CssClass = "hoverHeader";
th.Width = 120;
th.Text = "Feedback";
// set other properties
tr.Controls.Add(th);
// etc for other columns
table.Controls.Add(tr);
}
tr = new TableRow();
TableCell tc = new TableCell();
tc.Text = dt.Rows[i]["Provision"].ToString();
tr.Controls.Add(tc);
tc = new TableCell();
tc.Text = dt.Rows[i]["MarkForReview"].ToString();
tr.Controls.Add(tc);
tc = new TableCell();
tc.Text = dt.Rows[i]["IssueType"].ToString();
tr.Controls.Add(tc);
tc = new TableCell();
tc.Text = dt.Rows[i]["Resolution"].ToString();
tr.Controls.Add(tc);
tc = new TableCell();
tc.Text = dt.Rows[i]["Feedback"].ToString();
tr.Controls.Add(tc);
// add the button
tc = new TableCell();
Button button = new Button();
button.Text = "Edit";
button.ToolTip = Convert.ToString(i);
button.ID = dt.Rows[i]["TemplateID"].ToString() + "-" + dt.Rows[i]["ID"].ToString();
button.UseSubmitBehavior = false;
button.OnClientClick = "return false;";
button.Click += new EventHandler(btnEdit_OnClick);
tc.Controls.Add(button);
tr.Controls.Add(tc);
table.Controls.Add(tr);
}
MyContent.Controls.Add(acrDynamic);
所有这些都在持有人中使用,这解释了最后一行代码。
在ASP方面,我有持有者,加上一个modalpopupextender,当点击编辑按钮时会弹出一个模态窗体:
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="MyUpdatePanel" runat="server">
<ContentTemplate>
<asp:panel ID="MyContent" runat="server">
<!-- ************************************ -->
<ajaxtoolkit:modalpopupextender id="MdlCommentsExtender" runat="server"
targetcontrolid="MyContent" popupcontrolid="pnlComments"
popupdraghandlecontrolid="PopupHeader" drag="True"
backgroundcssclass="ModalPopupBG" Enabled="False" >
</ajaxtoolkit:modalpopupextender>
<asp:panel id="pnlComments" style="display: none" runat="server" BackColor="White" CssClass="modalPopup">
<div class="HellowWorldPopup">
<div class="PopupHeader" id="Div3" style="border: thin solid #000000; vertical-align: middle; text-align: center; background-color: #C0C0C0; color: #000000; font-weight: bold; height: 40px; width:499px;" ><br />Pend Comment</div>
<div class="PopupBody" style="background-color: #FFFFFF">
<table style="width: 490px">
<tr style="text-align:left">
<td style="padding:4px"><asp:Label ID="lblBenCat" runat="server" Text="Benefit Category:"></asp:Label></td>
<td style="padding:4px"><asp:Label ID="lblBenProv" runat="server" Text="Benefit Provision:"></asp:Label></td>
</tr>
<tr style="text-align:left">
<td style="padding:4px"><asp:Label ID="lblBenCatX" runat="server" Text="Benefit Category:"></asp:Label></td>
<td style="padding:4px"><asp:Label ID="lblBenProvX" runat="server" Text="Benefit Provision:"></asp:Label></td>
</tr>
<tr style="text-align:left">
<td colspan="2" style="padding:4px"><asp:Label ID="lblCommentBox" runat="server" Text="Feedback:"></asp:Label></td>
</tr>
<tr>
<td colspan="2" style="padding:4px">
<!-- <asp:TextBox ID="txtCommentBox_Old" runat="server" CssClass="textbox" TextMode="multiline" Wrap="True" Height="70px" Width="270px" Font-Size="Small"></asp:TextBox> -->
<asp:TextBox ID="txtCommentBox" TextMode="MultiLine" CssClass="textbox" Wrap="True" Height="70px" Width="270px" Font-Size="Small" Rows="3" runat="server" onkeyup="textCounter(this, this.form.remLen, 50);" onkeydown="textCounter(this, this.form.remLen, 50);" onpaste="textCounter(this, this.form.remLen, 50);" />
</td>
</tr>
<tr>
<td>
<input readonly="readonly" type="text" id="remLen" name="remLen" size="2" style="width:280px; " maxlength="3" value="50" /> characters left
</td>
</tr>
</table>
</div>
<div class="Controls" id="DivControls" runat="server">
<table style="width: 450px; align-items:center">
<tr>
<td style="vertical-align: middle; text-align: center"> <asp:Button ID="mdlCmntsOk_Clicks" runat="server" Text="Cancel" CssClass="textbox" Height="28px" Width="75px" OnClick="mdlCommentsOk_Click" /></td>
<td style="vertical-align: middle; text-align: center"> <asp:Button ID="mdlCmntsSave_Clicks" runat="server" Text="Save" CssClass="textbox" Height="28px" Width="75px" OnClick="mdlCommentsSave_Click" /></td>
</tr>
</table>
</div>
</div>
</div>
</asp:panel>
</asp:panel>
</ContentTemplate>
</asp:UpdatePanel>
<!-- ************************************ -->
</asp:Content>
所以这就是发生的事情;如果我注释掉button.OnClientClick = "return false;";
行,编辑按钮会弹出模态窗体,一切看起来都很棒,但Save和Cancel按钮都没有响应。大概是因为它做了回发。
为了阻止回发,我输入了上述button.OnClientClick
行。但现在编辑按钮什么都不做。
有没有办法让编辑按钮弹出该模态表单而不回发?它在Update面板中,我希望它能正常工作,但我假设我通过代码隐藏添加控件(它必须动态完成,因为数字可以根据用户的选择而改变)我缺少东西。