.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Setting Page properties from itself

Posted By:      Posted Date: October 08, 2010    Points: 0   Category :ASP.Net

Hi all,

Is there any easy way to set properties of a Page (or UserControl for that matter) from *within itself*?
As an example, I have several .aspx pages which inherit from exactly the same code-behind class, but I need to be able to pass different properties to the class to make them do the correct thing for the specific .aspx.

The only way I've found to do this is to create the following - which works fine, but doesn't feel right....
<script runat="server">
  Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
    Me.MyProperty = True
  End Sub

It would be a much nicer, simplier and easier solution to be able to be able to set MyProperty = True somewhere... is this possible?

The option of hard-coding properties within the class for the "parent" page is not going to work for my situation.

Many thanks in advance,
Tom Smile

View Complete Post

More Related Resource Links

Setting the default start page in godaddy hosting?


 How do you set the start page with godaddy hosting? I can see no way of doing this! You do not seem to have access to the IIS settings that allow you to change it!

Advanced Basics: Setting Word Document Properties the Office 2007 Way


The last time I wrote this column (March 2006), I shared an application that allows you to update all the Microsoft® Word documents in a folder and its subfolders. Each time the application finds a document in the specified path, it updates the document properties to match those you specified in the application.

Ken Getz

MSDN Magazine June 2006

User Control not accessing the value of the properties send to it from the aspx page.


I have a dynamic accordion on a page. Set its datasource to an object of paged data source.The user control is in the accordions content template. When i was writing code the properties were showing but after giving the values of databases as


<uc:UserControl1  runat="server" Property1='<%#DataBinder.Eval(Container.DataItem,"columname1")%>' Property2='<%#DataBinder.Eval(Container.DataItem,"columname2")%>'  ></uc:UserControl1>


but the values shows null, these properties are shown as textboxes text property by user control.

MoreOver when I checked the values of database Items.So i made a textbox instead of usercontrol here as

<asp:TextBox ID="txtTest" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Columname1")%>'></asp:TextBox>

It is showing the correct value. And if i pass the value directly it is also showing correctly like

<uc:UserControl1  runat="server" Property1="XYZ")%>' Property2="ABC")%>'  ></uc:UserControl1>

. where I am wrong

the problem is eval is not passing the value to usercont

The site master page setting currently applied to this site is invalid. Please select a new master p

I have defined a new master page and set it as default for the main site.  Any time I create a new subsite it does not apply the new master page and defaults back to the default.master.  The Site Master Page Settings shows this error. The site master page setting currently applied to this site is invalid. Please select a new master page and apply it The system master page setting currently applied to this site is invalid. Please select a new master page and apply it. Now if I select "Inherit site master page from parent of this site" and "Inherit system master page" and click ok the site will use the new master page and everything is fine.  There is only one modification to the master page that was done so I know the master page isn't invalid.  Does anyone know the answer other than recreating the new master page.

SPWeb.Properties is not persist over the redirect page.

Hi, I have to pass some object from my code to another redirected page. So I serialize the object and serialized string is save to SPWeb's property as a string and after that I use SPUtility.Redirect('Url'). But on redirected page above updated property is not find in the SPWeb.Property collection. string xml = MyClass.GetXMLFromObject(exInfo); SPContext.Current.Web.Site.RootWeb.AllowUnsafeUpdates = true; SPContext.Current.Web.Site.RootWeb.Update(); if (!SPContext.Current.Web.Site.RootWeb.Properties.ContainsKey("MyInfo")) { SPContext.Current.Web.Site.RootWeb.Properties.Add("MyInfo", xml); SPContext.Current.Web.Site.RootWeb.Update(); } else { SPContext.Current.Web.Site.RootWeb.Properties["MyInfo"] = xml; SPContext.Current.Web.Site.RootWeb.Update(); } SPContext.Current.Web.Site.RootWeb.AllowUnsafeUpdates = false; SPContext.Current.Web.Site.RootWeb.Update(); SPUtility.Redirect("RedirectToErrorPage/ApplicationPage1.aspx?ExInfo=" +xml, SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current); Redirected page code: if (SPContext.Current.Web.Site.RootWeb.Properties["MyInfo"] != null) { using (SPWeb web = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.Site.RootWeb.Url)) { TextBox1.Text = Convert.ToString(SPContext.Current.Web.Site.Root

Dynamic or Expression-based Report Page Properties

Hello, I have a tablix(table) with column grouping making the number of columns dynamic. Although our customers have been warned that this could lead to the columns going beyond the edge of the normal landscape 8.5x11 inch page, they have asked for alternate solutions. Beyond rotating the column labels and reducing fontsizes, the issue is not so much that it goes off the page, but the fact that in print preview mode the data is broken up requiring that you go to the next page to get the remaining data. What I am investigating is whether the Page Properties of the report body, either the pagesize property and/or the interactivesize property, can be manipulated at run time? This way if a user, based on their experience with the parameters they usually select and pass into the report, knows that the results will span the length of the page onto a second page, could choose a new parameter such as pagesize/interactivesize so that it changes from 8.5/11 to perhaps the next standard page size of 8.5/14 inches? This does not mean the contents would change during the course of rendering the report, just a new input that could decide at run time what paper size to use in print preview mode.   Thanks.

page.setfocus(listbox.selecteditem) is not setting the focus if index > 820

Hi All, Does any one know the reason Why I am unable to setfocus to my list box if the index > 820 My list box contains 2000 items and the index is not  able to set the focus if the index > 820  

change search results page According to custom setting page

I want to create user settings page will be able to choose which will  search results display page x or page y Settings will be saved somewhere. When the user searches on sharepoint search page will display to the user  the page that he select in the search page settings page x or  page y   my questions : 1. Is it necessary to treat the user profile - If so how? 2. how results can be directed to the search results page after a user choose Specific page? 3. where save the settings from custom settings page  ?

Documents link in Edit properties Page

Hi, my requirement is, the document library's editform should have a link to document like list's editform. please guide me to get this, Thanks in advance.

Setting custom master-page.


How can I set a custom master-page to a site or site-collection? There should be a link in site actions>site settings>look and feel called "master page" but Im not seeing it. Where is that exactly?


Styles: Setting Properties in deeper hierarchies


I'm not sure how to do a search on this, so I decided to rather ask it instead of doing hours of searching.

I have a class with DependencyProperties and use that class in a UserControl. I use that UserControl in a Window and in that Window I use the Window's Resources to set some Properties on the UserControl. I now like to set some DependencyProperties on that class, which would automatically reflect on the UserControl due the binding.

Is there a way to do it? I couldn't figure it out to do it in the .xaml, which is where I'd like to do this particular task.

How can I edit page properties in SP Designer 2010?


Is there any way to edit the page properties (metadata) in SP Designer?

setting dropdownlist item in page load


 I can't get the following to set on page load.  I want the month selected be the current month, on page load.  What needs to change here?

DropDownListCCExpMo.SelectedItem.Selected = Date.Today.Month


Modify the properties of all controls on a page at once?


I have a webform of fields.  This information is for a database modifying interface we're going to use internally, so the information that pops up is sensitive, and therefore in order to avoid any kind of stupid accidents, I've got the fields disabled initially.  Then there is an "Unlock" button which enables all of the fields if you do want to make a change.

My code behind looks something like this when the Unlock button is pressed:

    protected void UnlockClientFields()
        NameETextBox.Enabled = true;
        NameJTextBox.Enabled = true;
        GenInfoTextBox.Enabled = true;
        InstDirTextBox.Enabled = true;
        DBDirTextBox.Enabled = true;
        AddressTextBox.Enabled = true;
        StationTextBox.Enabled = true;
        MapTextBox.Enabled = true;

This works just fine.  No problems.  Question is, is this the most efficient way?  If we decide a field later, the only way to include that in the Locked --> Unlock function is to come in here and add it manually?  The reason I ask is that, we have multiple pages in this database modifying process, so I have essentially the same code as above, except for UnlockContactFields, UnlockPCFields, UnlockCaseFields, and so on.  A good portion of the code is just Unlock methods

Why do I get default error page desipite setting customErrors mode="Off"?


I could never figure it out -  set  <customErrors mode="Off" /> in all web.config files that exist under Interpub/wwwroot, but still get default error page. Which web.config does SharePoint use?

Setting properties from a database


 I have a database which holds the path of an image. It also holds the recomended height and width of the image. My question is how can I set the height and width properties from my database? I have tried the following with no avail:

<asp:TemplateField HeaderText="Image" HeaderStyle-HorizontalAlign="Left">
                    <asp:Image ID="Image" runat="server" ImageUrl='<%# Eval("Image") %>'  Width='<%# Eval("Width") %>' Height='<%# Eval("Height") %>'/>


Any Ideas?

Thanks in advance

Programmatically setting Agent Autostart properties


I've written a service to replace the SQL Server Agent service to be independent of Agent when moving to Express versions of SQL Server which do not include Agent.  Obviously on older 2000 MSDE versions I don't want Agent and my service running at the same time so I need to turn off Agent but there are SQL Server Properties such as under the General tab, "Autostart policies when the operating system starts" section and I need to uncheck the "Autostart SQL Server Agent".  In SQL Server Enterprize Manager I can right click the server then select properties and general tab.

How do I change that property either via T-SQL or via VB.NET to uncheck it?



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend