Monday, July 21, 2008

Importing namespace to the client-side code

Although client side code is not recommended to contain any code-behind code, some times it's required to write some server-side code on client-side file (aspx files). One example of this situation is when using  ASP.Net Repeater control; programmer might need to call a function to shape the fields to the required specification; therefore, the function has to be called on the aspx file. The need to access server-side code calls for importing namespaces. The problem here is the fact that imported namespaces to aspx.cs or aspx.vb are not seen by the same pages' aspx file.

Using the following piece of code will allow you to import namespaces to the aspx files to be used by server-side code.

<%@ Import Namespace="MyNamespace" %>

No comments: