473,813 Members | 2,514 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 3056
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
3596
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
3098
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
1378
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
1646
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
3634
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
1578
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
3488
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
2491
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
1364
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
9607
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,...
1
10424
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9224
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
7684
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
6897
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
5569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5706
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
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
3885
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.