将控制的值传递给模态弹出窗口

时间:2010-04-10 06:33:43

标签: c# .net asp.net asp.net-ajax

我想知道如何在ASP.NET中使用ModalPopUpExtender单击按钮后将文本框值传递给模式弹出窗口,我尝试过这些代码,但似乎我没有运气:(

 <script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick", "showModalPopup(); return false;");
    }
</script>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick='showModalPopup(); return false;' />

    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1"
        PopupControlID="Panel1" CancelControlID="btnCancel" OkControlID="btnOkay" BackgroundCssClass="ModalPopupBG">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="Panel1" Style="display: none" runat="server">
        <div class="HellowWorldPopup">
            <div class="PopupHeader" id="PopupHeader">
                Header</div>
            <div class="PopupBody">
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </div>
            <div class="Controls">
                <input id="btnOkay" type="button" value="Done" />
                <input id="btnCancel" type="button" value="Cancel" />
            </div>
        </div>
    </asp:Panel>

的javascript

 function showModalPopup() {
        //show the ModalPopupExtender
        var value;
        value = document.getElementById("TextBox1").value;
        $get("<%=Label1.ClientID %>").value = value;
        $find("<%=ModalPopupExtender1.ClientID %>").show(); 

    }

我想知道我错过了什么:(,谢谢,我希望有人可以帮助我:)。

1 个答案:

答案 0 :(得分:1)

使用

value = document.getElementById('&lt;%= TextBox1.ClientID%&gt;')。value;

而不是

value = document.getElementById(“TextBox1”)。value;