我有一个带有各种按钮的表单,当单击该表单时会显示一个模式弹出窗口。弹出窗口正确显示在屏幕上,但是任何字段中都没有数据。
单步执行代码时,我可以看到数据已分配给相关控件(文本框或标签),但是什么也没有显示。在我的项目中,我还有其他几种形式,它们也有弹出窗口,这些窗口应该可以正常工作。我什至用这些表格中的代码来尝试解决问题,但没有成功。
这是用户单击按钮以显示弹出窗口的代码
<div class="tab-pane fade" id="tabDiary">
<div class="col-md-12">
<asp:UpdatePanel ID="updatePanelDiary" runat="server">
<ContentTemplate>
<%--<asp:Timer ID="timerDiary" runat="server" Interval="15000" OnTick="timerDiary_Tick"></asp:Timer>--%>
<asp:Repeater ID="rptDiary" runat="server" OnItemDataBound="rptDiary_ItemDataBound">
<HeaderTemplate>
<div class="col-md-12 text-right">
<div class="form-group">
<asp:Button ID="btnDiary" runat="server" Text="New Diary Item" OnClick="btnDiary_Click" CssClass="btn btn-warning" Visible="true" />
<div class="clearfix"></div>
</div>
</div>
<table class="table table-striped table-bordered">
<thead>
<tr class="tabHeaderRow">
<td>Date</td>
<td>Entered By</td>
<td>Comments</td>
<td>Action Date</td>
<td></td>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"DateEntered") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"AddedBy") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"Comments") %></td>
<td><asp:Label ID="lblActionDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ActionDate") %>'></asp:Label></td>
<td><asp:Button ID="btnEditDiaryEntry" runat="server" CssClass="btn btn-primary btn-sm" Text="Edit" CommandName="EditDiaryEntry"
OnCommand="btnEditDiaryEntry_Command" CommandArgument='<%#Eval("DiaryID") %>' /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="clearfix"></div>
</div>
这是背后的代码:
protected void btnEditDiaryEntry_Command(object sender, CommandEventArgs e)
{
Int32 DiaryID = Convert.ToInt32(e.CommandArgument);
SqlCommand cmd = new SqlCommand("sp_GetDiaryEntry", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DiaryID", DiaryID);
cnn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
txtEditComment.Text = dr["Comments"].ToString();
txtEditScheduleDiary.Text = dr["ActionDate"].ToString();
}
dr.Close();
cnn.Close();
ScriptManager.RegisterStartupScript(_parentControl, _parentControl.GetType(), "Modal", " DisplayEditDiaryModal()", true);
Master.GetMenuData();
txtEditScheduleDiary.Text = "hello david";
}
这是显示弹出窗口的代码
<script type="text/javascript">
function DisplayEditDiaryModal() {
$('#<%=pnlDiaryEdit.ClientID%>').modal('show');
}
</script>
这是模态代码:
<asp:Panel ID="pnlDiaryEdit" runat="server" class="modal fade" role="dialog">
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="well well-md">
<fieldset>
<legend class="text-center header"><asp:Label ID="Label31" Text="Edit Diary Entry" runat="server" Visible="true"></asp:Label></legend>
<asp:HiddenField ID="hidDiaryID" runat="server" />
<div class="form-group">
<div class="col-md-3">
<asp:Label ID="lblEditComment" runat="server" Text="Comment"></asp:Label>
</div>
<div class="col-md-9">
<asp:TextBox ID="txtEditComment" runat="server" CssClass="form-control" TextMode="MultiLine" Rows="10" Wrap="true" ></asp:TextBox>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<div class="col-md-3">
<asp:Label ID="lblEditSchedule" runat="server" Text="Schedule Event"></asp:Label>
</div>
<div class="col-md-6">
<asp:TextBox ID="txtEditScheduleDiary" runat="server" CssClass="form-control" Visible="true" ></asp:TextBox>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group">
<div class="col-md-12 text-right">
<asp:Button ID="btnCancelEdit" runat="server" Text="Cancel" CssClass="btn btn-primary" OnClientClick="HideEditDiaryModal(); return false;" />
<asp:Button ID="btnEditDiary" runat="server" Text="Edit" CssClass="btn btn-success" OnClick="btnEditDiary_Click" />
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
正如我已经说过的那样,此代码可在项目中的其他表单上运行。任何帮助将不胜感激。
答案 0 :(得分:0)
您是否尝试过添加updatePanelDiary.Update()?
protected void btnEditDiaryEntry_Command(object sender, CommandEventArgs e)
{
Int32 DiaryID = Convert.ToInt32(e.CommandArgument);
SqlCommand cmd = new SqlCommand("sp_GetDiaryEntry", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DiaryID", DiaryID);
cnn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
txtEditComment.Text = dr["Comments"].ToString();
txtEditScheduleDiary.Text = dr["ActionDate"].ToString();
}
dr.Close();
cnn.Close();
ScriptManager.RegisterStartupScript(_parentControl, _parentControl.GetType(), "Modal", " DisplayEditDiaryModal()", true);
Master.GetMenuData();
txtEditScheduleDiary.Text = "hello david";
updatePanelDiary.Update();
}
并将UpdateMode =“ Conditional”添加到您的更新面板中
<asp:UpdatePanel ID="updatePanelDiary" runat="server" UpdateMode="Conditional">