本文介绍了从子弹出窗口向父窗体发布数据(使用刷新的父窗体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从子弹出窗口向父窗体发布数据(带有刷新的父窗体)



我有两个文本框和一个父窗体的按钮,带有标题OPEN child。我在一个文本框中输入了数据。对于其他文本框我想从子弹出窗口中获取数据,该弹出窗口将在单击按钮时打开。在子弹出窗口中,我有一个文本框和一个按钮。将在此文本框中输入的数据将在单击按钮的父文本框中显示。数据来自子弹出,但父表单正在刷新,我不想要。当数据进入其他文本框throgh子弹出窗口时,我希望数据在第一个文本框中保持不变。请给我一个建议。



以下是我试过的代码。但它对我不起作用。



设计级别Sample1.aspx页面的示例代码:



Post Data from child popup to parent Form (With out refreshing parent Form)

I have two textbox and one button in parent form with caption OPEN child. I had entered data in one textbox. for other textbox i want to take data from child popup which will open on clicking the button. In child popup, I have one textbox and one button. The data which will be entered in this textbox will come in parent textbox on clicking button. Data is coming from child popup but the parent form is getting refreshed which i dont want. I want data to remain intact in first textbox when data will come in other textbox throgh child popup. Plese give me a suggestion.

Below is the code which i tried. But it is not working for me.

Sample code for Sample1.aspx page at desgin level :

<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <form id="form1" runat="server">
            <table>
                <tr>
                    <td>First Name:</td>
                    <td><asp:TextBox ID="txtName1" Runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Qualification:</td>
                    <td><asp:TextBox ID="txtName2" Runat="server"></asp:TextBox></td>
                </tr>

                <tr>
                    <td align="center" colspan="2">
                    <asp:Button ID="btnSubmit" Runat="server" PostBackUrl="Sample2.aspx" Text="Submit" /></td>
                </tr>
            </table>
        </form>
    </body>
</html>





Sample2的示例代码.aspx页面在Desgin级别:





Sample code for Sample2.aspx page at Desgin level :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample2.aspx.cs" Inherits="Sample2" %>
<%@ PreviousPageType VirtualPath="~/Sample1.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
        <div align="center">
                   <asp:Button ID="btnBack" Runat="server" PostBackUrl="Sample1.aspx" Text="Back" />
            </div>
    </form>
</body>
</html>





代码级Sample2.aspx的示例代码:





Sample code for Sample2.aspx at Code level :

protected void Page_Load(object sender, EventArgs e)
{
    //-- If posted from Sample1.aspx to Sample2.aspx page
    if (PreviousPage != null)
    {
        if (PreviousPage.IsCrossPagePostBack)
        {
            //-- Retrieve the textbox values from Previous page using FindControl method

            TextBox TextBox2;



            TextBox2 = (TextBox)PreviousPage.FindControl("txtName2");

           TextBox2.Text = "MBBS";//This value should be in textbox2 in sample page1 without lossing value of textbox1
        }
        else
        {
            Response.Redirect("Sample1.aspx");
        }
    }
}





提前致谢。



Thanks in advance.

推荐答案

imgTool.Attributes.Add("onclick", string.Format("popupOpen({0})", txtbox1.ClientID));





这是你可以在你的主页面添加的javascript代码,这个scriipt将是一个popop window.kindly更改页面名称到你的弹出式aspx窗口。



This is javascript code which you can add in your main page and this scriipt will a popop window.kindly change the page name to your popup aspx window.

function popupOpen(textbox_id) {
    if (project_id.disabled || project_id.getAttribute('ReadOnly')) return false;
    var res = ShowPopup("popUpPage.aspx?project_id=" + project_id.value, 820, 551);
    if (!!res) {
        textbox.value = res[0];
       // if (!!car_cd) textbox.value = res[1]; 
    }
}





在弹出页面中,您可以关闭按钮并关闭按钮单击。传递需要在主页面中显示的结果。





In you Popup Page you can have close Button and in Close Button Click.pass the result which need to be display in your main page.

protected void btnConfirm_Click(object sender, ImageClickEventArgs e)
    {
        SelectConfirm("Shanu");
    }
 protected void SelectConfirm(yourreturnvalue)
    {
     Response.Write("<script language='javascript'>");
        Response.Write("window.returnValue = new Array('" +
       yourreturnvalue  + "');window.close();");
     Response.Write("</script>");
    }


这篇关于从子弹出窗口向父窗体发布数据(使用刷新的父窗体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 01:24
查看更多