如何以编程方式设置放置在由ModalPopupExtender控制的Panel中的Web控件的属性

时间:2012-03-07 11:06:44

标签: asp.net panel modalpopupextender

我有一个ASP.NET Web窗体应用程序。在我的GridView OverviewGridView 中,有一个按钮 dlButton ,onclick触发一个控制Panel dlModalPanel 的ModalPopupExtender DisplayLinkMPE 。在 dlButton 单击后,当我弹出 dlModalPanel 时,我想显示一些文本(根据GridView的行而有所不同)。我在我的aspx中有这段代码:

<asp:Button ID="dlButton" runat="server" CommandName="DisplayLink" CommandArgument="<%# TryCast(Container,GridViewRow).RowIndex %>" Text="Copy Link" />
<ajax:ModalPopupExtender ID="DisplayLinkMPE" runat="server" TargetControlID="dlButton" PopupControlID="dlModalPanel" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" />

 <asp:ScriptManager ID="ModalDialogScriptManager" runat="server" />
    <asp:Panel ID="dlModalPanel" runat="server" Style="display: none;">
        <table>
            <tr align="center">
                <td colspan="2">
                    <asp:Label ID="lblDownloadLink" runat="server" ForeColor="White">Copy Download Link:</asp:Label>
                    <asp:Label ID="txtDownloadLink" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>

dlButton 后面的代码中,单击由 OverviewGridView RowCommand 事件处理程序处理,该事件处理程序在页面回发之后执行:< / p>

Dim selectedRowIndex As Integer = Convert.ToInt32(e.CommandArgument)

Dim displayLinkMPE As AjaxControlToolkit.ModalPopupExtender = OverviewGridView.Rows(selectedRowIndex).FindControl("displayLinkMPE")

//Get itemUrl

txtDownloadLink.Text = itemUrl
displayLinkMPE.Show()

所有内容都正确显示,但 txtDownloadLink 中的文字仍为空。如何更新此文字?感谢

我也理解C#所以欢迎两种语言的答案!

1 个答案:

答案 0 :(得分:1)

查看Matt Berseth撰写的这篇优秀文章Check it here,我认为你必须使用更新面板&amp;将您的模态代码包装在其中,然后使用

手动更新UpdatePanel
upatePanel1.Update();
  1. 检查此link以获取其他示例
  2. 修改检查完整的工作示例。您必须手动更新模式弹出更新面板以查看对文本框的任何更改。 ASPX

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link rel="Stylesheet" type="text/css" href="css/StyleSheet.css" />
        <style type="text/css">
            .modal
            {
                background-color: Aqua;
                width: 150px;
                height: 100px;
                padding: 6px;
            }
            .modalBackground
            {
                background-color: #CCCCFF;
                filter: alpha(opacity=40);
                opacity: 0.5;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:UpdatePanel ID="upnGrid" runat="server">
                <ContentTemplate>
                    <asp:ScriptManager ID="ScriptManager1" runat="server">
                    </asp:ScriptManager>
                    <asp:GridView CssClass=".Grid-blue" ID="GridView1" runat="server" AllowPaging="True"
                        AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="LinqDataSource1">
                        <Columns>
                            <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
                                ReadOnly="True" SortExpression="ProductID" />
                            <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                            <asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
                            <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
                            <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
                            <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
                            <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
                            <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
                            <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
                            <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:LinkButton ID="lbEdit" runat="server" OnClick="lbEdit_Click">Edit</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
            </asp:UpdatePanel>
            <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext"
                EntityTypeName="" TableName="Products">
            </asp:LinqDataSource>
        </div>
        <ajaxToolkit:ModalPopupExtender BackgroundCssClass="modalBackground" ID="mpeDetails"
            CancelControlID="btnClosePopup" TargetControlID="btnShowModal" PopupControlID="pnlDetails"
            runat="server">
        </ajaxToolkit:ModalPopupExtender>
        <asp:Button ID="btnShowModal" runat="server" Text="Button" Style="display: none" />
        <asp:Panel ID="pnlDetails" CssClass="modal" runat="server" Style="display: none">
            <asp:UpdatePanel ID="upnDetails" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <label>
                        ID:</label><asp:TextBox ID="txtID" runat="server"></asp:TextBox>
                    <br />
                    <label>
                        Name:</label>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    <br />
                </ContentTemplate>
            </asp:UpdatePanel>
            <div>
                <asp:Button ID="btnClosePopup" runat="server" Text="Cancel" /></div>
        </asp:Panel>
        </form>
    </body>
    </html>
    

    .CS

       protected void lbEdit_Click(object sender, EventArgs e)
    {
        LinkButton lbTemp = (LinkButton)sender;
    
        if (lbTemp != null)
        {
            GridViewRow grow =(GridViewRow) lbTemp.NamingContainer;
            int id = Convert.ToInt32(GridView1.DataKeys[grow.RowIndex][0].ToString());
            mpeDetails.Show();
            txtID.Text = id.ToString();
            upnDetails.Update();
        }
    }