c# - How to get a business class property value in jquery variable -
i need business class property value java script variable. using value iam doing manipulations. here have tried creating object , string in aspx page unable acess string "val" in java script. how access ?
aspx file:
<%@ page language="c#" autoeventwireup="true" codebehind="webform1.aspx.cs" inherits="webapplication1.webform1" %> <!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"> <% webapplication1.business obj = new webapplication1.business(); %> <% string val = obj.name; %> <head runat="server"> <title></title> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function () { $("#btnsubmit").click(function(){ alert("welcome"); var valproperty = <%= val%>; alert("val property : "+ valproperty); $("#txtname").val(valproperty); }); }); </script> <form id="form1" runat="server"> <div> <input type="text" id="txtname" /> <br /> <input type="button" id="btnsubmit" value="get server property value" /> </div> </form> </body> </html>
class file:
public class business { public string name { get; set; } public string money { get; set; } }
i think you're accessing fine, haven't set obj.name
<% webapplication1.business obj = new webapplication1.business(); %> // assign obj.name here <% string val = obj.name; %>
Comments
Post a Comment