从modalpopupExtendet中的文本框返回值到没有刷新的父页面 [英] Return Value from a textbox in modalpopupExtendet to the Parent Page without Refresh

查看:75
本文介绍了从modalpopupExtendet中的文本框返回值到没有刷新的父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将modalpopupextendet的文本框中的值返回到父页面的文本框而不刷新页面。



I am trying to return value from a modalpopupextendet's textbox to the parent page's textbox without a page refresh.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
   <style type="text/css">
        .modalbackground
        {     background-color:Gray;
              opacity: 0.5;
              filter:Alpha(opacity=50);
        }
        .modalpopup
        {
            background-color:White;
            padding:6px 6px 6px 6px;
        }
   </style>
</head>
<body>

    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        &nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Text="Button" />

        <asp:Panel ID="Panel1" runat="server" CssClass="modalpopup">
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
            <asp:Button ID="Button2" runat="server" Text="Ok" />&nbsp;&nbsp;
            <asp:Button ID="Button3" runat="server" Text="Cancel" />
        </asp:Panel>

        <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalbackground"

         TargetControlID="Button1" PopupControlID="Panel1" CancelControlID="Button3">
        </asp:ModalPopupExtender>

    </div>
    </form>
</body>
</html>





Button2 点击页面执行操作刷新我不想要的。

另外如果我向modalpopupextender添加更多按钮,点击那些按钮,modalpopupextender关闭



我希望modalpopupextender仅在Button2点击事件时关闭,返回一个值而不刷新页面

modalpopupextender上的任何控件都不应该关闭它。



on "Button2" click the page does a refresh which I don't want.
Also If I add more buttons to the modalpopupextender and on click of those buttons the modalpopupextender closes

I want the modalpopupextender to close only on the Button2 click event returning a value without refreshing the page
no othe controls on the modalpopupextender should close it.

推荐答案

在你的代码后面写:



In your code behind write:

Button2.Attributes.Add("onclick","return ShowData();");
Button3.Attributes.Add("onclick","return ClosePopup();");



在以下脚本中添加以下脚本您的aspx页面的head部分:


Add the following script in the head section of your aspx page:

<script language="javascript" type="text/javascript">
function ShowData()
{
var txtValue = document.getElementById("TextBox2").value;
alert(txtValue);
return false;
}
function ClosePopup()
{
alert('Close button clicked.');
return false;
}
</script>





请记住,TextBox的ID必须是生成的ID在HTML(查看客户端ID的页面源),因为它在面板内。它可能会改变。或者,您可以在JavaScript中使用Control.ClientID属性。



Remember, the ID of your TextBox has to be the ID generated in HTML(view source of your page for client ID) since it is inside a panel. It may change. Alternatively, you can use Control.ClientID property in JavaScript.


这篇关于从modalpopupExtendet中的文本框返回值到没有刷新的父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆