Web Forms :: Setting Page Properties From Itself?

Oct 8, 2010

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
</script>

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.

View 2 Replies


Similar Messages:

State Management :: Master Page's Treeview Selected Node / Setting The Properties In Master Page?

Aug 2, 2010

I have a master page containing a tree and 3 dropdown lists. I am populating a context menu on right click of each node, and when clicked on any item of the context menu, it navigates to required pages.

My problem is after navigating to the required page, the selected values from the drop down lists and the selected node from the tree are getting cleared.

I can set the selected values for the dropdown lists by making some properties in master page.
But how do i maintain the selected node?

In my content page, i have got the valuepath of the right clicked node.

Or is there any other way than setting the properties in master page?

View 6 Replies

Web Forms :: Setting Properties During Design?

Jan 15, 2010

i have a WebControl class called ContentFrame that has a Header property and a Content property.

public WebControl Header {get; set;}
public WebControl Content {get; set;}

Now let's say that I have form x and ContentFrame is on the form. What I want to do is be able to set the the Header and Content properties during design time in the source

<cc1:ContentFrame ID="ContentFrame1" runat="server">
<Header>
<WebControl></WebControl>
</Header>
<Content>
<WebControl></WebControl>
</Content>
</cc1:ContentFrame>

View 5 Replies

Web Forms :: Asp:hyperlink In New Windows And Setting Properties?

Jan 6, 2011

hyperlink in new windows and setting properties

View 1 Replies

Web Forms :: Setting The Properties Of USerControl From Values In C#?

Dec 15, 2010

I have some user controls which have properties which need to be set from a form on the page

<uc1:MyPlugin
ID="MyPlugin2"
runat="server"
Property1="Hi"
Property2="0" Property3="<%=Property3%>"
Property4="<%#Property4
%>"
/>

Property3 and Property4 anre both public properties of the page I am on and the user control

Currently the code complaing about Property3 saying it cannot create an object of Int32 from '<%=Property3%>' and Property4 always gets set to 0 (the default)

I do not wish to use the c# code to set these values as this Plugin will be deployed with a CMS which I have no control over

View 3 Replies

Web Forms :: Setting Properties Within BasePage Class Not Working?

Jan 11, 2010

We are trying to use a BasePage class (which inherits from Page) to populate and set the Meta Keywords and Meta Description Tags. I am using masterpages and below is an example code extract... According to examples on the internet, I could then set this also via the Page Directive using the MetaKeywords and MetaDescription properties, but they do not appear.

I have tried setting the CodeFileBaseClass="MyNamespace.UI.BasePage" but this does not work either. Using debug I can see that the BasePage classes' MetaKeywords and MetaDescription properties are not being set within my content page. I can access the properties but not set them.

== BASEPAGE CLASS ==

[Code]....

== PAGE CLASS ==

[Code]....

View 3 Replies

Forms Data Controls :: Setting Properties From A Database?

Oct 4, 2010

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:

[Code]....

View 6 Replies

Web Forms :: Dynamic User Control And Setting Properties?

Jan 25, 2011

I have a user control (i.e. ascx) that comprises of two related list boxes (i.e. once you change the selected item in one list the contents of the other list update). I'm adding this user control dynamically to a page on the click event of a button (i.e. using LoadControl).I wish to set the list box datasource properties, as well as the default selected item of the parent list from my parent page so I created public properties in my user control to accomodate this. I also created an event in my user control that notifes the parent page when the selected item changes in one of the list boxes so I can update the contents of the other list box.

I understand that I have to recreate the user control on every postback in order for it to function correctly but I'm not sure exactly how I should be doing it. I've shown below what I have currently - whilst it works the problem is that on postback I'm always creating the user control with all its default properties and then updating the properties that need to change(?). For example, when the choice in theparent list box changes the datasource of the list box is set twice (once in AddControl and then again in OnParentChanged)? As the contents of the list boxes originate in a database it means I'm making unnecessary calls to the database (unless I do some something like store each unique set of data in the ViewState).

I'd be very grateful if someone could review how I've done things and illustrate how perhaps I should be doing things. I'm not sure if the way I've done this is considered the 'correct' way. For example there may be a better way of doing things would avoid setting the properties twice? I'm a bit unsure of the way I've set the datasource properties of the list boxes and bound them. I wished to set the datasource from the parent page because I might have a second user control on my page that may also use the same datasource and I could reuse it (as opposed to each control making its own call to the database) so I'd like to keep this feature if possible.It would be great if posting code in reply that you use my example as a guide so I know what you're referring to.Here's the code for my user control:

[Code]....

[Code]....

Here's the code for my containing page:

[Code]....

View 1 Replies

Web Forms :: Finding Control Id And Setting Properties In Other Pages?

Oct 23, 2010

im using a webusercontrol (hide.ascx) it has 2 buttons btn_hide,btn_expand

and in my other forms of all like(products.aspx)customers.aspx,orders.aspx

im using a panel conrol(pnl_products) where in im placing all the input controls.

i want to find the panel control in hide.ascx page and to set that

panel.visble=true/false property in this page.

View 2 Replies

Forms Data Controls :: Setting Bound Field Properties?

Mar 11, 2011

eI am using themes to set the Gridview font size and font name. I need to set the boundfield to the same font and size as I want it to be application to all the columns in gridview. How can I specify the boundfield properties in the themes.

View 8 Replies

Web Forms :: Setting Properties On A Dynamically Loaded Control As Template?

Jan 6, 2010

[Code]....

Once the template is loaded and cast back to the TabHeader class, it's null. How can I load that control, set the properties, and use it as the template? Or is the only way to go about doing this to create a custom class?

View 2 Replies

Forms Data Controls :: Setting Properties On Web User Control In Dynamic GridView

Jan 7, 2010

I am in need of some assistance in regards to how to best set the values of properties for a Web User Control which is being included into a cell of a GridView with dynamically created columns. I have tried a few different approaches, but can't seem to get a satisfactory result. Also, to be completely honest, I am not really sure if I am using best practices for what I am trying to accomplish.

First off a little background:I have a GridView for which we will never know the exact number of columns at run time. The columns are predicated by user selection. I am creating the command text for the DataSet on the fly and then looping through the columns of the resulting DataTable in order to use custom TemplateFields. This works ok for just printing out the row values but not so much for when I need to insert the Web User Control into a cell.The Web User Control is in essence a collection of image links which are used as a "Quick Nav" tool. I need to pass the values of 2 fields from each DataRow to the control via properties (for example, CustID and ProductID). I am using custom TemplateField classes inheriting from ITemplate for displaying my fields and extending the DataBinding event like so: [Code]....

This won't work for my User Control as DataBinding is called after the control is loaded into the page and I need the properties to be set before the Page_Load event of the control is fired.Is there a GridView event I should be looking into instead such as RowCreated or RowDataBound? Or should I modify how I loop through the DataTable by doing rows first, then the resulting columns as I've seen done elsewhere?

View 5 Replies

Order Of Precedence In Setting Properties?

Feb 4, 2010

Some settings in asp.net like viewstate can be controlled at the site (web.config), page, or control levels. What is the order of precedence? What happens, for example, if I set viewstate of site and page levels but on at the control level?

Also, is viewstate for a control the same as control state? Furthermore, what events to use for loading and saving viewstate for controls (is this the same thing as control state?) and also for custom controls?

Similarly, which events should I use to render controls? Is this PreInit and Load? Is this the same for custom controls?

View 1 Replies

Intellisense When Setting A Value On Custom Properties

Dec 6, 2010

I have the following property:

[Code]....

I want to be able to have the user see the available options when they try to do something such as DateRange = .... (i want intelllisense in here and I can set the values). Is this a possible functionality? I am using VS 2008 .NET 3.5

View 1 Replies

C# - Setting Custom Control Properties?

Apr 20, 2010

I though it would be very simple but I can not get it today.I have a user control, with a grid control contained in it.

public Unit Width
{
get

[code]...

View 1 Replies

DataBind Versus Setting Control Properties

Nov 9, 2010

Regarding these two approaches:

<asp:Label ID="Label1" runat="server"><%# DateTime.Now %></asp:Label>

and

Label1.Text = DateTime.Now.ToString();

Which do you use and why?

View 2 Replies

Setting Values For Invisible Fields / Properties In DetailsView?

Mar 16, 2011

I have a DetailsView which has two fields - one that is visible, one that is not. The first the user fills out, the second I want to auto-populate. Unfortunately, I haven't been able to find a way to set the value in this second invisible field. I've tried adding code like this to the Page_Load:

If Not IsPostBack Then
DetailsView1.DefaultMode = DetailsViewMode.Insert
Dim txt1 As TextBox = DirectCast(DetailsView1.FindControl("Type"), TextBox)
txt1.Text = "administrator"
End If

But this returns an error of "Object reference not set to an instance of an object." how to accomplish this - either using the method above or another method? The hoped for end result is that when a new record is inserted via the DetailsView that this record will include the username (entered by the user) as well as the "type" of "administrator"

View 2 Replies

DataSource Controls :: Setting Common Properties For An ObjectDataSource?

Nov 7, 2010

In my ASP.NET application I am using a lot of ObjectDataSource controls. I want to set the following three properties globally for all ObjectDataSource controls:

EnableCaching="true"

View 5 Replies

Web Forms :: Can Modify The Properties Of A Content Page Control From An Event Fired From The Master Page?

Feb 25, 2011

Can I modify the properties of a content page control from an event fired from the master page?create a delegate and event on master page wire up the master page in the content page create the event handler (function) on the content page modify for example:

contents of the Text property of a textbox render a control visible (or hidden) etc...

View 4 Replies

Web Forms :: Properties Folder / Properties Changed No Settings Tab?

Nov 3, 2010

I have a new VS2010 .NET 4.0 Web project and the Properties Folder has gone wierd on me. It has lost teh "Open" under the right click. There is no way to get a Settings file created now.

I am unable to get to the Settings grid and no Settings file is created. I tried the help and it has the normal trip of select Properties, Open (right click), Settings Tab, etc. etc.

View 1 Replies

Web Forms :: Setting Page Index When Working With Multiple DataGrids On Page

Jul 18, 2012

I have 2 DataGrid in a single page.

First DataGrid contain 2 page and 10 records per page

Second DataGrid contain 5 page and 10 records per page

When i click 3rd page of second DataGridthe following error occur

"Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount."

public partial class Admin_Over_all_report : System.Web.UI.Page {
Dataconnection dc = new Dataconnection();
protected void Page_Load(object sender, EventArgs e) {
if (IsPostBack == false) {
bind();

[Code] ....

View 1 Replies

Web Forms :: Master Page Properties Not Working Correctly?

Feb 3, 2010

In my default.aspx I have;

<%@ Page Title="" Language="VB" MasterPageFile="~/masterpage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" AspCompat="true" %>
<% @ MasterType VirtualPath ="~/masterpage.master" %>

I have setup properties, for example;

Private _theskin As String
Public Property theskin() As String
Get
Return _theskin
End Get
Set(ByVal value As String)
_theskin = String.Empty
End Set
End Property

I was then expecting to be able to access these properties from the default.aspx.vb page in this way;

If Master.theskin = foo Then
do things
End if

In the default.aspx.vb the code is highlighted with blue underline and says;

theskin is not a member of system.Web.Ui.Masterpage

Am I making an error somewhere along the line? Do I need to do more to be able to expose the properties to default.aspx.vb?

View 2 Replies

Web Forms :: Pass The View State Properties From One Page To Another?

Feb 11, 2010

How can we pass the View State properties from one ASP.NET page to another in ASP.NET?

View 4 Replies

Web Forms :: Access Public Properties Of Master From Content Page?

Mar 9, 2010

Here's the scenario: A class based on System.Web.UI.Page has been created. A number of content pages derive from this class. All of these content pages use the same master page. The content pages define controls which need to access things on the master page (in code-behind). This is fine - no problem. In particular, each content page has its own data grid. The grid on each page has the same name, so that common code can reference it. In fact, some event handling for the grids on each content page is identical, so would like to factor that code to the base class. Interestingly, I can actually define the event handler entirely in the base class, with no stub in the content class at all, because the wire-up of event handlers uses the event-handler name defined in the grid, and that name happens to be found in the inherited base class. All good and dandy... very cool in fact. The problem comes when the code in the base class needs to access any of the common elements from the content page's master. Remember, the master is the same, and I know the type of the master. I would like to do something like this in the base-class code:

((myMasterType)this.Master).PropertyofMaster=xxx;

The problem is, that myMasterType - the type of the master page the content pages are using - is not available at compile time, at least not from a class definition for a base page. I've found articles that claim that the class name of the master is available - and it is, but not from a separate class. I CAN see it and compile with the master's class name from, for example, the code behind of the various content pages. But the actually class simply isn't available, it seems, from a pure class (the base page class). Judging from other times this question has been asked, here are common misunderstandings offered as solutions: 1. Use a page directive to declare the master type. This is not even vaguely a part of the problem, as the issue is not code in the content page, but in a separate base class which content pages inherit from. That base class is a pure class -- no .ASPX file at all. 2. Pass a reference to the master object from the content page to the base class. This can be done, but is pointless, because I can already get it, using "this.Master" from the base class! But because the type of the master is not available at compile time from the base class, it can't be passed from the content page either - unless it is passed with type MasterPage, thus losing all the properties/methods publically defined in the specific master page class. 3. Move the base page class out of the App_Code folder because the app_code folder is compiled before the other classes, and thus before the master page class. Doesn't work -- put the master page class file right in the same folder with these content pages and their master page, and the master page class is still not available at compile time from within the class. Re-summarized: Base page inherited by content pages. Content pages all use a common master page. Want to access the public properties of that master page from the base page, at runtime. Barrier is that I can find no way from within the base class to cast the master page object to the actual master page subclass being used.

View 7 Replies

Web Forms :: Can't Access Master Page Properties In Visual Studio?

Oct 8, 2010

I have created a Master Page and exposed a Literal control on it by way of a public property.

[Code]....

In my content page I have referenced the Master Page like so :

[Code]....

However in my content page code behind I cannot see the custom properties of the master page in Visual Studio.

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved