none
ASP.NET Web Forms FAQ: Bagaimana cara untuk mengambil variabel server-side menggunakan kode JavaScript RRS feed

  • Diskusi Umum

  • <asp:HiddenField ID="HiddenField1" runat="server" />  

     

      public partial class LoginDemo : System.Web.UI.Page 

      {    

        private string str="hello"; 

        protected void Page_Load(object sender, EventArgs e) 

        { 

            HiddenField1.Value=str; 

        } 

    }

     

    Kemudian Anda dapat mengakses control HiddenField1 menggunakan javascipt:

     

    <script type="text/JavaScript"> 
    Var tt=document.getElementByID(“HiddenField1”); 
    alert(tt.value); 
    </script>
     

    Thread terkait: http://forums.asp.net/p/1000655/1319119.aspx  


    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, 03 Agustus 2011 08.58
    Moderator