将数据传递到ModalPopupExtender

问题描述:

我有一个ModalPopupExtender,它允许客户应用付款信息.它一直都很棒.然后,客户要求在ModalPopup上查看应付总额.仅仅从父控件中获取应付金额并将其传递到ModalPopup控件中似乎并不重要.似乎没有简单的方法可以做到这一点.

I have a ModalPopupExtender that allows a customer to apply payment info. It has been working great. Then the customer asked to see the total due on the ModalPopup. This did not seem like a big deal to just take the total due from the parent control and pass it into the ModalPopup control. It seems like there is no easy way do to this.

这是我的HTML代码,请记住,此代码包装在UpdatePanel中

Here is my HTML code, keep in mind this code is wrapped in a UpdatePanel

<asp:LinkButton ID="lnkMakePayment" runat="server" Visible="true" OnClick="lnkMakePayment_Click" >

<asp:Label ID="lblMakePayment" runat="server" Text="Make Payment"/></asp:LinkButton>

<asp:Button ID="btnDummy" style="display: none;" runat="server" 
            OnClick="btnDummy_Click" />

<ajaxToolkit:ModalPopupExtender ID="mdlPopupPayment" runat="server" 
 TargetControlID="btnDummy" PopupControlID="pnlMakePayment"
 CancelControlID="popUpCancel" DropShadow="true" BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>

 <asp:Panel ID="pnlMakePayment" runat="server" Style="display: none;"
            SkinID="PopUpPanel" class="ContentBoxColor" Width="400px" Height="170px">
    <MP1:MakePaymentPopup ID="MakePayment"  runat="server" />
    <div style="text-align: right; width: 100%; margin-top: 5px;">
       <asp:Button ID="popUpCancel" runat="server" Text="Cancel" Width="0px" />
    </div>
 </asp:Panel>

现在这是隐藏的代码

protected void btnDummy_Click(object sender, EventArgs e) { }

protected void lnkMakePayment_Click(object sender, EventArgs e)
{
    mdlPopupPayment.Show();
} 

因此,当用户单击付款"链接时,ModalPopup可以正常工作.甚至触发父控件监听应用付款信息和用户在弹出窗口中填写的所有相关付款详细信息的事件.同样,这一切都很好.

So when the user clicks the make payment link the ModalPopup works fine. And it even fires an event that the parent control listens for to apply payment info and all the associated payment details that the user fills out in the popup. Again this all works fine.

由于ModalPopup,我第一次尝试发送总数如下:

My first attempt at sending the total due to the ModalPopup is as follows:

protected void lnkMakePayment_Click(object sender, EventArgs e)
{
    // MakePayment is the actual ModalPopup control and total due is a public property
    MakePayment.TotalDue = txtTotalDue.Text
    mdlPopupPayment.Show();
} 

此问题是,当我单击链接以显示ModalPopup时,不会触发PageLoad事件,因此无法将属性分配给ModalPopup内的标签. 我什至尝试使用会话对象,但存在相同的问题. 我什至无法访问数据库,因为我无法传递客户ID. 有任何想法吗? 我是Javascript的新手,并且可以使服务器端受益匪浅,但是在这一点上,我愿意尝试任何事情.

The problem with this is that when I click the link to show the ModalPopup the PageLoad event does not fire so I have no way to assign my property to a label inside the ModalPopup. I even attempted to use the session object but had the same issue. I can not even make a trip to the database because I can not pass in a customer ID. Any ideas? I am a novice at Javascript and perfer a server side soultion but at this point I am willing to try anything.

MakePayment用户控件包含3个ASP文本框.一个用于用户输入付款金额,另一个用于输入付款类型,第三个用于输入票据(如支票号码).控件上还有一个应用"和取消"按钮.父控件是一个基本的ascx页面,它是一个数据输入屏幕,其中包含ModalPopupExtender和所有用于激活它的html代码.

The MakePayment user control contains 3 asp textboxes. One for the user to input a payment amount, another for payment type, and a third for notes like check numbers. Also on the control there is an apply and cancel button. The parent control is a basic ascx page which is a data entry screen that contains the ModalPopupExtender and all html code to activate it.

一旦我意识到自己做错了什么,我想出的解决方案就非常简单了. 我必须感谢Arnold Matusz,因为他的博客文章向我展示了光芒. http://blog.dreamlabsolutions. com/post/2009/01/10/ModalPopupExtender-to-show-a-MessageBox.aspx

Once I realized what I was doing wrong the solution I came up with was pretty straight forward. I must thank Arnold Matusz for it was his blog entry that showed me the light. http://blog.dreamlabsolutions.com/post/2009/01/10/ModalPopupExtender-to-show-a-MessageBox.aspx

与其让ModalPopup entender调用只显示一些html的用户控件,还不如使它成为一个控件.我做了一个用户控件,即ModalPopupExtender.这样,我可以调用它并传递一些数据.

Instead of having the ModalPopup entender call a user control that just displayed some html. I made a user control that was the ModalPopupExtender. This way I can call it and pass in some data.

我的MakePayment用户控件的HTML看起来像

My MakePayment user control's HTML looks like

<asp:Button ID="btnDummy" style="display: none;" runat="server"  
   OnClick="btnDummy_Click" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopupPayment" runat="server"  
            TargetControlID="btnDummy" PopupControlID="pnlMakePayment" 
            CancelControlID="popUpCancel" DropShadow="true"
            BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="pnlMakePayment" runat="server" Style="display: none;"  
    SkinID="PopUpPanel" class="ContentBoxColor" Width="400px" Height="170px">
<div class="contentbox">
    <div class="contentboxHeader1">
        <asp:Label ID="lblPopupTitle" Width="350px" runat="server" Text=""></asp:Label>
    </div>
    <div class="contentbox">
        <div style="text-align: left">
            <asp:Label ID="lblTotalDue" Width="100px" runat="server" Text="">  
            </asp:Label>
            <asp:Label ID="lblTotalDueValue" Width="100px" runat="server">
            </asp:Label>
         </div>
        <div style="text-align: left">
            <asp:Label ID="lblPayment" Width="100px" runat="server" Text=""></asp:Label>
            <asp:TextBox ID="txtPayment" Width="100px" runat="server"></asp:TextBox>
            <ajaxToolkit:FilteredTextBoxExtender ID="ftbePayment" runat="server" 
               TargetControlID="txtPayment" FilterType="Custom, Numbers" 
                 ValidChars="."> </ajaxToolkit:FilteredTextBoxExtender>
        </div>
        <div style="text-align: left">
            <asp:Label ID="lblPaymentRefNo" Width="100px" runat="server" Text=""> 
            </asp:Label>
            <asp:TextBox ID="txtPaymentRefNo" Width="100px" runat="server">
            </asp:TextBox>
        </div>
        <div style="text-align: left">
        <asp:Label ID="lblPaymentType" Width="100px" runat="server" Text=""></asp:Label>
            <asp:TextBox ID="txtPaymentType" Width="250px" runat="server"></asp:TextBox>
        </div>
    </div>
    <div class="contentbox" style="text-align=right">
        <asp:Button ID="btnApplyPayment" runat="server" Text="" 
             OnClick="btnApplyPayment_Click" />
        <asp:Button ID="btnCancel" runat="server" Text="" OnClick="btnCancel_Click" />
    </div>
</div>
<div style="text-align: right; width: 100%; margin-top: 5px;">
    <asp:Button ID="popUpCancel" runat="server" Text="Cancel" Width="0px" />
</div>
</asp:Panel>

在后面的代码中,我有一个公共方法

And in the code behind I have a public method

public void MakePayment(string szAmountDue)
{
    lblTotalDueValue.Text = szAmountDue;
    mdlPopupPayment.Show();
}

在主表单上,我有一个名为付款"的链接

On my main form I have a link called Make Payment

<asp:LinkButton ID="lnkMakePayment" runat="server" Visible="true" 
      OnClick="lnkMakePayment_Click" >
     <asp:Label ID="lblMakePayment" runat="server" Text=""/>
</asp:LinkButton>

单击付款"链接后,后面的代码将调用MakePayment控件,以传递我希望显示的任何数据.

When the Make Payment link is clicked the code behind calls the MakePayment control passing in any data I wish to display.

protected void lnkMakePayment_Click(object sender, EventArgs e)
{
    MakePayment.MakePayment(lblTotalValue.Text.ToString());
}