C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Substitution control


Posted Date: 04 Nov 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: krishnavenikaladiMember Level: Gold    
Rating: 1 out of 5Points: 5



Description :


It is used to display dynamic content on cached webpage.

Basic requirements of using Substitution Control:

The control requires input as static method with HTTPCONTEXT as parameter and should return String.

Step 1:
Create a database table:

Create table news (msg varchar(50));

Populate it with data.

Step 2:
Degign a web form with a label and substitution control.
Set the method name of substitution control to the method name.
Method code:
It should be coded under public static string (Http Context c)


//defining connection object
OracleConnection cn = new OracleConnection("user id=scott;password=tiger;data source=ganesh1");
//defining command object
OracleCommand cmd = new OracleCommand("select * from news", cn);
//instantiating the string object
string news = string.Empty;
//opening the connection
cn.Open();
//executing the statement(only one row is retrieved
news = cmd.ExecuteScalar().ToString();
//closing the connection
cn.Close();
//returning string
Return "<marquee>" + news + "</marquee>";
//code in page load
//projecting text
Label1.Text = "cached time" + DateTime.Now.ToString();


Step 3: Set cache in the source of web page

<%@ OutputCache Duration ="10" VaryByParam ="none" %>


Step 4: Excute the web form

Step 5: Update the database

Step 6: Now execute the web form


Excited!!!!!!!!!!!now you wonder! The output is with last update message.

Explanation:
--->The above snippet develops connection with database and retrieves the data
--->If data is updated .....substitution control is used to display updated data.(using method which is static )



Responses

Author: ABitSmart    04 Nov 2009Member Level: Diamond   Points : 0
Please format your resource


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Http context  .  Executescalar  .  Dataset  .  Connection  .  Command  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Downloads (pushes) file to the client browser.
Previous Resource: Cache
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use