ASP.NET Getting Started FAQ: Bagaimana untuk memperbarui data pada halaman lain? RRS feed

  • Diskusi Umum

  • Bagaimana anda mengubah data pada halaman dan memperbarui data yang terkait pada halaman lain?

    anda mempunyai dua halaman. Salah satunya adalah halaman utama dan lainnya adalah halaman popup. Halaman Popup dibuka oleh halaman utama melalui ' ()'. 


    Main page:

    <form id="form2" runat="server"> 

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 

    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> 

    <asp:Button ID="Button1" runat="server" Text="Button" /> 



     private void Page_Load(object sender, EventArgs e) 
        //Create client side function for update 
        StringBuilder str = new StringBuilder(); 
        str.Append("&lt;script language=javascript>"); 
        str.Append("function update(e){"); 
        str.Append("document.getElementById('" + TextBox1.ClientID + "').value=e[0];"); 
        str.Append("document.getElementById('" + TextBox2.ClientID + "').value=e[1];}"); 
        // register the JavaScript into the Page 
        if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "update")) 
            Page.RegisterClientScriptBlock("update", str.ToString()); 
        Button1.Attributes.Add("onclick", "'Popup.aspx',null,'left=400, top=100,  height=250, width= 250, status=no, resizable= no, scrollbars= no, toolbar= no,location= no, menubar= no');"); 




    <form id="form3" runat="server"> 


        <input id="Text1" type="text" /><input id="Text2" type="text" /> 

        <asp:Button ID="Button1" runat="server" Text="Button"  /> 




    private void Page_Load(object sender, System.EventArgs e) 
        string str = @"&lt;script language=javascript> 
        function toValue() 
            var text1=document.getElementById('Text1').value; 
            var text2=document.getElementById('Text2').value; 
            var ar= new Array(text1,text2); 
        if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "toValue")) 
            ClientScript.RegisterClientScriptBlock(this.GetType(), "toValue", str.ToString()); 
        Button1.Attributes.Add("onclick", "toValue();"); 


     Thread terkait:

    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Rabu, 27 Juli 2011 03.31