简体   繁体   English

在模态弹出窗口扩展器的父页面中设置值

[英]Set value in Parent Page from Modal Popup Extender

I am testing the ModalPopupExtender in a simple web application. 我正在一个简单的Web应用程序中测试ModalPopupExtender。 The user should input a value in the modalpopup and then this value would be shown in the parent page after closing the modal popup. 用户应在模式弹出窗口中输入一个值,然后在关闭模式弹出窗口后在父页面中显示该值。

I used this code for the design: 我将以下代码用于设计:

<body>
    <form id="form1" runat="server">
      <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:Button runat="server" ID="BtnOpenPopup" Text="Open Popup" />
        <asp:Label runat="server" ID="lbl" ></asp:Label>
        <asp:Panel runat="server" ID="PnlTest">
           <asp:TextBox runat="server" ID="txtInput"></asp:TextBox>             
           <asp:Button runat="server" ID="BtnSubmit" Text="Submit" OnClick="BtnSubmit_Click" />
        </asp:Panel>
        <ajaxToolkit:ModalPopupExtender runat="server" TargetControlID="BtnOpenPopup" EnableViewState="true" OkControlID="BtnSubmit" PopupControlID="PnlTest" ></ajaxToolkit:ModalPopupExtender>
      </div>
    </form>
</body>
</html>

And this is my code behind: 这是我的代码背后:

 protected void BtnSubmit_Click(object sender, EventArgs e)
 {
    lbl.Text = txtInput.Text;
 }

This didn't work, I don't get any errors, but still the lbl isn't loaded with the user input. 这行不通,我没有收到任何错误,但用户输入仍未加载lbl。

Would appreciate if you can give me some insight on how this works. 如果您能给我一些有关此工作原理的信息,将不胜感激。

Hello I guess that you have to add a script for the OnOkScript attribute, try this : 您好,我想您必须为OnOkScript属性添加脚本,请尝试以下操作:

   //......
   //.......

   <ajaxToolkit:ModalPopupExtender runat="server" 
        TargetControlID="BtnOpenPopup" 
        EnableViewState="true" 
        OkControlID="BtnSubmit" 
        PopupControlID="PnlTest" 
        OnOkScript="onModalOk();"> <!-- here is the tag you have to add to get it work -->

    </ajaxToolkit:ModalPopupExtender>
  </div>
</form>
<script>
    function onModalOk()
    {
        document.getElementById("lbl").innerText = document.getElementById('txtInput').value;
    }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM