Monday, April 30, 2012

How to Access the Property of aspx.cs page to javascript...



For Example Create a Web Page..

.aspx page code



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function GetValue() {
            var value = "<%=Name %>";
            alert(value);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="btngetvalue" Text="GetValue" OnClientClick="GetValue();" runat="server"/>
    </div>
    </form>
</body>
</html>




aspx.cs Page code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Property
{
    public partial class Property : System.Web.UI.Page
    {
        private string _name;
      
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
       protected void Page_Load(object sender, EventArgs e)
       {
           Name = "Kartik";
       }
    }
}


Now run page and check the alert message.you will get the value of aspx.cs page propery.

0 comments:

Post a Comment