2015-11-05 44 views
0

我正在測試一個簡單的Web應用程序中的ModalPopupExtender。用戶應該在modalpopup中輸入一個值,然後這個值會在關閉模式彈出框後顯示在父頁面中。從Modal Popup Extender的父頁面設置值

我用這個代碼的設計:

<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> 

而這背後是我的代碼:

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

這沒有工作,我沒有得到任何錯誤,但仍是lbl沒有加載用戶輸入。

如果你能告訴我一些關於它是如何工作的見解,我將不勝感激。

+0

你檢查:http://stackoverflow.com/questions/2177227/need -help -with-a-simple-asp-net-modalpopupextender-example –

+0

@Eray,謝謝,但是這個問題在鏈接中與我的無關。 – user3340627

回答

2

你好,我想,你必須添加腳本爲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> 

相關問題