Print C# properties in aspx,ascx page from code behind file.

Hello all

Today I will show you how to print something in aspx or ascx page from code behind file.In this example I have taken a “Web User Control” named “WebUserControl.ascx”. What I wanted to do was, print a value of a variable in “.ascx” page where the variable has been initialize from “.ascx.cs” better to say code behind file.

To do that we have taken a property in “WebUserControl.ascx.cs” code behind file named “PrintValue” and make it a public property and assign a string value on PageLoad event as bellow :

Now I have printed the value of the property in my “WebUserControl.ascx” page as bellow.One thing we have to remember that the script tag should be like : <%= %> to print something in it.

Now we can use the control in our page to show the state of the page.
Thats all for today.

User ScrumPad for your Agile based projects.