Ajax 模态弹出窗口出现两次
Ajax Modal pop up appears twice
我在 gridview 中有一个链接按钮,当我单击该链接按钮时,应该会出现一个模式弹出窗口。但是当我点击时,模态弹出窗口出现了两次,下面是我的代码。
ASPX:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<asp:GridView ID="gvAppIssue" runat="server" AllowPaging="True" AutoGenerateColumns="False"
ForeColor="#333333" GridLines="Both" OnRowCommand="gvAppIssue_RowCommand"
PageSize="100" ShowHeaderWhenEmpty="true" EmptyDataText="No Records Found" EmptyDataRowStyle-Font-Bold="true"
EmptyDataRowStyle-HorizontalAlign="Center" CsssClass="contentfont">
<Columns>
<asp:TemplateField HeaderText="App ID">
<ItemTemplate>
<asp:Label ID="lblAppID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="App Name">
<ItemTemplate>
<asp:Label ID="lblAppName" runat="server" Text='<%# Eval("App") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Issue" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnIssue" runat="server" ForeColor="Black"
Text='<%# Eval("App_Iss") %>' CommandName="checkAppIss" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="White" />
<PagerStyle HorizontalAlign="Center" BackColor="#5B95CF" ForeColor="White" />
<HeaderStyle BackColor="#5B95CF" Font-Bold="True" ForeColor="White" Width="80%" />
</asp:GridView>
<asp:Panel ID="pnlIssue" runat="server" BackColor="Gainsboro" CssClass="contentfont">
<table align="center">
<tr>
<th valign="middle" colspan="2" align="center" bgcolor="#1E4265" style="font-weight: bold;
font-size: medium; font-family: Arial; color:white;">
Issue Details
<asp:ImageButton ID="btnWarning" runat="server" ImageUrl="Images/Close.PNG" ImageAlign="Right"
Height="20px" Width="20px" />
</th>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="App ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="AppName" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppName" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:HiddenField ID="hfpop" runat="server" />
<cc1:ModalPopupExtender ID="popup" CancelControlID="btnWarning" runat="server" PopupControlID="pnlIssue"
TargetControlID="hfpop" >
</cc1:ModalPopupExtender>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
隐藏代码:
protected void gvAppIssue_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "checkAppIss")
{
GridViewRow gvRow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
string strID = ((Label)gvRow.FindControl("lblAppID")).Text;
if(strID == "Yes")
{
int appID = "1";
ShowPopup(appID);
}
}
}
}
根据 strID 值,我需要检查 table 中的某些行,然后我将值填充到 ShowPopup
方法中的标签。
public void ShowPopup(int appID)
{
DataTable dtGetID = AppData.GetID(appID);
if (dtGetID.Rows.Count > 0)
{
lblAppID.Text = dtGetID.Rows[0]["Id"].ToString();
lblAppName.Text = dtGetID.Rows[0]["Name"].ToString();
popup.Show();
}
}
现在我能够在标签中获得正确的值,唯一的问题是弹出窗口出现了两次。一个弹出窗口具有完整的值,它是完美的,另一个弹出窗口只有第一个 td 值,而不是 showpopup 方法中的标签。所以我不得不关闭一个弹出窗口才能看到另一个完美的模式。
任何人都可以建议或帮助我解决这个问题吗?
这可能是由于回发问题。也许尝试将 "pnlIssue"、modul popup extender 和 hidden field 放置在 gridView 更新面板之外和它们自己的更新面板中,在面板的更新面板上设置 UpdateMode="Conditional" 并调用 updatepanelName.Update显示弹出窗口。
例如
<asp:UpdatePanel ID="upPopup" ChildrenAsTriggers="false" RenderMode="Inline" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Panel ID="pnlIssue" runat="server" BackColor="Gainsboro" CssClass="contentfont">
<table align="center">
<tr>
<th valign="middle" colspan="2" align="center" bgcolor="#1E4265" style="font-weight: bold;
font-size: medium; font-family: Arial; color:white;">
Issue Details
<asp:ImageButton ID="btnWarning" runat="server" ImageUrl="Images/Close.PNG" ImageAlign="Right"
Height="20px" Width="20px" />
</th>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="App ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="AppName" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppName" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:HiddenField ID="hfpop" runat="server" />
<cc1:ModalPopupExtender ID="popup" CancelControlID="btnWarning" runat="server" PopupControlID="pnlIssue"
TargetControlID="hfpop" >
</cc1:ModalPopupExtender>
</ContentPanel>
</UpdatePanel>
后面的代码:
public void ShowPopup(int appID)
{
DataTable dtGetID = AppData.GetID(appID);
if (dtGetID.Rows.Count > 0)
{
lblAppID.Text = dtGetID.Rows[0]["Id"].ToString();
lblAppName.Text = dtGetID.Rows[0]["Name"].ToString();
popup.Show();
upPopup.Update();
}
}
我在 gridview 中有一个链接按钮,当我单击该链接按钮时,应该会出现一个模式弹出窗口。但是当我点击时,模态弹出窗口出现了两次,下面是我的代码。
ASPX:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<asp:GridView ID="gvAppIssue" runat="server" AllowPaging="True" AutoGenerateColumns="False"
ForeColor="#333333" GridLines="Both" OnRowCommand="gvAppIssue_RowCommand"
PageSize="100" ShowHeaderWhenEmpty="true" EmptyDataText="No Records Found" EmptyDataRowStyle-Font-Bold="true"
EmptyDataRowStyle-HorizontalAlign="Center" CsssClass="contentfont">
<Columns>
<asp:TemplateField HeaderText="App ID">
<ItemTemplate>
<asp:Label ID="lblAppID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="App Name">
<ItemTemplate>
<asp:Label ID="lblAppName" runat="server" Text='<%# Eval("App") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Issue" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnIssue" runat="server" ForeColor="Black"
Text='<%# Eval("App_Iss") %>' CommandName="checkAppIss" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="White" />
<PagerStyle HorizontalAlign="Center" BackColor="#5B95CF" ForeColor="White" />
<HeaderStyle BackColor="#5B95CF" Font-Bold="True" ForeColor="White" Width="80%" />
</asp:GridView>
<asp:Panel ID="pnlIssue" runat="server" BackColor="Gainsboro" CssClass="contentfont">
<table align="center">
<tr>
<th valign="middle" colspan="2" align="center" bgcolor="#1E4265" style="font-weight: bold;
font-size: medium; font-family: Arial; color:white;">
Issue Details
<asp:ImageButton ID="btnWarning" runat="server" ImageUrl="Images/Close.PNG" ImageAlign="Right"
Height="20px" Width="20px" />
</th>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="App ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="AppName" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppName" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:HiddenField ID="hfpop" runat="server" />
<cc1:ModalPopupExtender ID="popup" CancelControlID="btnWarning" runat="server" PopupControlID="pnlIssue"
TargetControlID="hfpop" >
</cc1:ModalPopupExtender>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
隐藏代码:
protected void gvAppIssue_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "checkAppIss")
{
GridViewRow gvRow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
string strID = ((Label)gvRow.FindControl("lblAppID")).Text;
if(strID == "Yes")
{
int appID = "1";
ShowPopup(appID);
}
}
}
}
根据 strID 值,我需要检查 table 中的某些行,然后我将值填充到 ShowPopup
方法中的标签。
public void ShowPopup(int appID)
{
DataTable dtGetID = AppData.GetID(appID);
if (dtGetID.Rows.Count > 0)
{
lblAppID.Text = dtGetID.Rows[0]["Id"].ToString();
lblAppName.Text = dtGetID.Rows[0]["Name"].ToString();
popup.Show();
}
}
现在我能够在标签中获得正确的值,唯一的问题是弹出窗口出现了两次。一个弹出窗口具有完整的值,它是完美的,另一个弹出窗口只有第一个 td 值,而不是 showpopup 方法中的标签。所以我不得不关闭一个弹出窗口才能看到另一个完美的模式。
任何人都可以建议或帮助我解决这个问题吗?
这可能是由于回发问题。也许尝试将 "pnlIssue"、modul popup extender 和 hidden field 放置在 gridView 更新面板之外和它们自己的更新面板中,在面板的更新面板上设置 UpdateMode="Conditional" 并调用 updatepanelName.Update显示弹出窗口。
例如
<asp:UpdatePanel ID="upPopup" ChildrenAsTriggers="false" RenderMode="Inline" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Panel ID="pnlIssue" runat="server" BackColor="Gainsboro" CssClass="contentfont">
<table align="center">
<tr>
<th valign="middle" colspan="2" align="center" bgcolor="#1E4265" style="font-weight: bold;
font-size: medium; font-family: Arial; color:white;">
Issue Details
<asp:ImageButton ID="btnWarning" runat="server" ImageUrl="Images/Close.PNG" ImageAlign="Right"
Height="20px" Width="20px" />
</th>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="App ID" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label runat="server" Text="AppName" Font-Bold="true"></asp:Label>
</td>
<td>
<asp:Label ID="lblAppName" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:HiddenField ID="hfpop" runat="server" />
<cc1:ModalPopupExtender ID="popup" CancelControlID="btnWarning" runat="server" PopupControlID="pnlIssue"
TargetControlID="hfpop" >
</cc1:ModalPopupExtender>
</ContentPanel>
</UpdatePanel>
后面的代码:
public void ShowPopup(int appID)
{
DataTable dtGetID = AppData.GetID(appID);
if (dtGetID.Rows.Count > 0)
{
lblAppID.Text = dtGetID.Rows[0]["Id"].ToString();
lblAppName.Text = dtGetID.Rows[0]["Name"].ToString();
popup.Show();
upPopup.Update();
}
}