views:

271

answers:

2

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
+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
Person would need to be at least a protected member for the ASPX to access it.
batwad
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
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