i know i have seen this but cant recall the correct way of doing it... basically i have a string variable called "string clients" in my .cs file.. but i wasn't to be able to pass it to my aspx page something like
<%=clients%>
please correct me, i do not recall or not sure how to do this. (new to c#) and when i googled it.. it was not clear.. or not many of these out there.. searched as
"asp.net c# <%= %>
not consistent results.. maybe because i do not know how to call these..
aspx page must specify to inherit from the code-behind base class. To do this, use the Inherits attribute for the @ Page directive. The . aspx page inherits from the code-behind class, and the code-behind class inherits from the Page class.
If you need to pass the value from the code-behind to the HTML page, you can use a hidden field for the relay. Then, you can get the value from the HiddenField1 via document. getElementById("HiddenField1").
The field must be declared public
for proper visibility from the ASPX markup. In any case, you could declare a property:
private string clients; public string Clients { get { return clients; } }
UPDATE: It can also be declared as protected
, as stated in the comments below.
Then, to call it on the ASPX side:
<%=Clients%>
Note that this won't work if you place it on a server tag attribute. For example:
<asp:Label runat="server" Text="<%=Clients%>" />
This isn't valid. This is:
<div><%=Clients%></div>
In your code behind file, have a public variable
public partial class _Default : System.Web.UI.Page { public string clients; protected void Page_Load(object sender, EventArgs e) { // your code that at one points sets the variable this.clients = "abc"; } }
now in your design code, just assign that to something, like:
<div> <p><%= clients %></p> </div>
or even a javascript variable
<script type="text/javascript"> var clients = '<%= clients %>'; </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With