Binding the value from code behind to aspx file in C#


1. If we want to bind string value to javascript

For example in code behind we have 
public string name=" raju";

<script type="text/javascript">
    
 var AuthorName = "<%=name%>";         
  alert(AuthorName.tostring());
</script>

2. In code behind we have a method returning value

protected string GetValue()
{
   return "raju";
}
 
then in aspx we can get value by
 
<asp:HiddenField ID="hdnId" runat="server" Value='<%# GetValue() %>'/> 
 
 
 
other way is directly place this  '<%#name%>' 


No comments:

Post a Comment