473,888 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add Page Directives Programmaticall y?


I would like to set the following Page directives in my C# code-behind
for ASP.NET 2.0 Web Application Project and also in a ASP.NET 2.0 Web
Site. What event should I hook and what should the code look like?

MaintainScrollP ositionOnPostba ck
ViewStateEncryp tionMode
LinePragmas
Title
Thanks.
Sep 13 '06 #1
3 3058
xeroxero,

The first two are simple:

Page.MaintainSc rollPositionOnP ostBack = true;
Page.Title = "hello";

The page ViewStateEncryp tionMode property complains with an exception if you
try to set it manually: "The 'ViewStateEncry ptionMode' property can only be
set in the page directive or in the <pagesconfigura tion section"

Probably for security reasons, if a page has been configured to require
encrypted viewstate... well... allowing the code to change this would be
incorrect (given that the declaritive security requirements should override
requirements expressed in code). So... you're out of luck there.

However there is the "RegisterRequir esViewStateEncr yption()"... which will
force the veiwstate to be encrypted. This must be done in prerender or
before.

As to LinePramas... I think you're out of luck. LinePragmas is more of an
instruction to the ASP.NET compiler (the one that produces pure C#/VB.NET
code that is then compiled by .net). By the time your code is running...
it's already way too late (code has been generated and compiled).

Regards,

Rob MacFadyen

"xeroxero" <xe******@newsg roups.nospam wrote in message
news:kr******** *************** *********@4ax.c om...
>
I would like to set the following Page directives in my C# code-behind
for ASP.NET 2.0 Web Application Project and also in a ASP.NET 2.0 Web
Site. What event should I hook and what should the code look like?

MaintainScrollP ositionOnPostba ck
ViewStateEncryp tionMode
LinePragmas
Title
Thanks.


Sep 14 '06 #2
Thank for Rob's informative suggestions.

Hi Xeroxero,

I think Rob has answered all your questions completely.

Just some add on to the ViewState encryption, if you want to use
Page.RegisterRe quiresViewState Encryption to programmaticall y set ViewState
be encrypted, you need to ensure the "viewStateEncry ptionMode" is set as
Auto(default setting) in @page directive or web.config. You can get some
more detailed description about ViewState encryption in ASP.NET 2.0 and its
related settings in the following msdn article:

#How To: Configure MachineKey in ASP.NET 2.0
http://msdn.microsoft.com/library/en...7.asp?frame=tr
ue

As for the "LinePramas ", I'm afraid Rob is right, this is a pure compile
time specfic setting and at runtime, we haven't any means to configure
it(even if we have such a property, it's too late at runtime to control
compilation behavior).

If there is any other information you wonder, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 14 '06 #3
Hello Xeroxero,

Have you got any further ideas on this question or does our reply help you
a little? If there is anything else we can help, please feel free to post
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3599
by: seemanta dutta | last post by:
Greetings C gurus, I have used preprocessor directives since a very long time. But whenever I see some professional piece of C code, the linux kernel for example, I get literally confused by the amount of preprocessor directives used in these code. Can anyone please tell me how to actually use these preprocessor directives in a more professional way like selecting particular lines of code suited for some particular hardware etc...
2
3101
by: Cris Curtis | last post by:
When I use an embed tag that uses a dynamic aspx page, the dynamic aspx page appears to get called 2 times instead. Below is code that adds an embed tag to a placeholder control that will use a second aspx page to generate the svg for the embed. svgchart.Controls.Clear(); string strSRC = "./DesktopModules/Enterprise/BusinessRuleSVG.aspx";
1
1379
by: DotNetWorks | last post by:
Does anyone know of a way to insert a directeve from the code behind? Background: I an creating a custom web control that wraps the IE Web control tab strip. The tab strip will still use the IE web control tab items but the tab strip container will be custom. So I will
3
1650
by: Janaka | last post by:
Hi All, I'm having a problem with Page Output caching on a page that contains a DataGrid. Basically the page pulls up some data for sales information from the DB. Some of this has to be calculated on the fly when the request is made, and so I thought it would be ideal to cache the page for a set amount of time. I've placed the following at the top of my page: <%@ OutputCache Duration="160" VaryByParam="None" %> Now the problem is...
2
3636
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
1
1579
by: Leo Muller | last post by:
I am impressed by the caching performance of .NET. However, there is one major obstacle that I haven't managed to solve yet. What I want to do is the following: I have a normal site, and a preview site. The normal site should have maximum performance, thus uses caching. The preview site is for internal use only, and should not use caching, since our content managers will want to see the updates directly. The only difference between the...
14
3495
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... I want to completely seperate the code from presentation. I would like to do the same thing for a value of a hidden form field but
3
2495
by: DC | last post by:
Hi, (ASP.Net 1.1) is it possible to (programmatically and globally) deactivate page fragment caching? We have only two scenarios, development stage where we want caching off and testing where we want caching on. Is this doable? I think there is a config switch in 2.0, anything in 1.1? TIA for any hint,
5
1366
by: homertbush | last post by:
When our asp.net pages are rendered out as html the page directive is still in the html. ie. The following page directive is present in the body of the html of the rendered page: <%@ Page CodeBehind="about.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="Briggs.about" %> <%@ Register TagPrefix="uc1" TagName="WebUserControlSearch" Src="WebUserControlSearch.ascx" %>
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.