Is databind, bind or eval... only way of getting data form code behind (server side) in ASP.NET
A:
you could use sessions, querystring, control parameter like in your datasources
<asp:SessionParameter />
<asp:QueryStringParameter />
<asp:ControlParameter />
<asp:CookieParameter />
but the concept is both .aspx and .cs are partial class and merge at runtime
check these links.. Codebehind and Compilation in ASP.NET 2.0
Muhammad Akhtar
2009-11-26 09:45:47
+2
A:
No you can expose any data from the code using server tags. For example if you have a property in the codebehind thats an object called Person you can expose it like so
<p>Hello your name is <% =Person.Name%></p>
Edit: Any properties or methods can be accesses in this way as the aspx page essentially inherits from the codebehind class, but the accessors will need to be set to at least protected as a result
Sheff
2009-11-26 09:46:03
Person would need to be at least a protected member for the ASPX to access it.
batwad
2009-11-26 09:57:30
batwad make a valid point. As the aspx page is enssentally inherited from the of .cs any methods or properties access would at least need to be protected. Thanks for pointing this out.
Sheff
2009-11-26 10:05:22
Just for completeness' sake: the <%= %> construct can be used interchangeably with <% Response.Write(Person.Name); %>And yet another way is to emit client-side hidden fields/arrays/variables, but that is definitely appropriate only for a small set of use cases.
Veli
2009-11-26 12:02:08