Adding a property to a user control, setting property at design time, then using value in control markup

 I have made a custom control that outputs a bunch of html. I have added a property through the code behind like this: 

    private string sectionID;

public string SectionID
{
get
{
return sectionID;
}
set
{
sectionID = value;
}
}
 This property is now showing up in Intellisense, and I can specify the value when adding the control to my page like this: 
<ccl:MyControl runat="server" SectionID="2" />
 I now want to use this value in the markup that the control outputs. I think I have the wrong syntax. Can someone please check? This doesn't build: 
<div id="section<%# SectionID; %>" >
 

Disco Patrick writes web applications using:

Visual Studio 2008
ASP.NET 3.5
C#
SQL Server 2008
0
Disco
2/25/2009 3:28:24 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

6 Replies
1206 Views

Similar Articles

[PageSpeed] 44

I'm no expert in fact I am waiting for an anwer to one of my questions, but

in your case what I would probably do is create your div at runtime then you will be able to get the value which can be added as the id

 


jnc
0
jnc
2/25/2009 5:37:27 PM

 I appreciate you can create these things at runtime.

However, if it is possible to do in a way that is similar to what I am trying to do, i.e. by injecting the value into the markup, I would like to know about it.

If it is not possible, I would like someone to confirm this so I can move on!

Thanks.


Disco Patrick writes web applications using:

Visual Studio 2008
ASP.NET 3.5
C#
SQL Server 2008
0
Disco
2/25/2009 8:14:54 PM

I understand, this builds on mine, I have not attempted to reference the new id in the div which I presume is what what you want to do 

you might try passing the value to a hidden field then getting the value from the field using getelementbyid("hiddenfield").innettext
 <div ID='<%# DataBinder.Eval(Container, "DataItem.AppData") %>' >
   <asp:Button ID="Button1" runat="server" Text="Button" />
</div>

you might try passing the value to a hidden field then getting the value from the field using a javascript function, can I ask why you want to do this?

 


jnc
0
jnc
2/26/2009 12:06:09 PM

 Hi jnc,

Here's the full story... I tried to create a complex form using the Wizard web control. However I soon discovered that this control outputs its HTML in tables. I wasn't happy with this, so set about creating my own page to reflect the functionality of the Wizard.

So I created a div for each section of the form, in the same way that  the Wizard has a WizardStep for each section. The code inside each of these divs was the same, so I decided to create a user control that I could re-use. Each div contains a number of questions that are taken from the database. Each question belongs to a specific section, which is why I added the SectionID property to the control, so the control would only fetch the questions related to that section.

Then I created my own sidebar to switch between sections - just like the Wizard sidebar. The buttons call a javascript function, passing a section number to the function. The function then un-hides the correct div by looking for the div that has an id of "sectionN". And that is why I need to give each div a specific ID!!!

This is what I need to understand:

jnc:

<%# DataBinder.Eval(Container, "DataItem.AppData") %>' >



Can you explain this syntax to me? Did you have to set up anything in the code-behind to make this work? What is DataItem?

Disco Patrick writes web applications using:

Visual Studio 2008
ASP.NET 3.5
C#
SQL Server 2008
0
Disco
2/26/2009 12:42:25 PM

 I found this to work: 

<%# DataBinder.Eval(Container.DataItem, "columnName") %>
 Turns out you don't need to set up any additional stuff.

Disco Patrick writes web applications using:

Visual Studio 2008
ASP.NET 3.5
C#
SQL Server 2008
0
Disco
2/26/2009 1:06:26 PM

good news

I did once do a database driven page which collected the data in code behind then built a grid using a <table>, I added IDs to each cell similar to spreadsheet coordinates but all, as I said in code behind

I used javascript to control the editing and extract the values

 


jnc
0
jnc
2/26/2009 1:25:02 PM
Reply:

Similar Artilces:

Set User Control Properties at run time (for same user control used more than once on the same page)
I have a user control which contains some textboxes and radio buttons. I have created public properties on the user control so that they can be access from the page using the UserControl.I load the user control dynamically into my parent page. I do this 3 times for the same user control, and I set the properties for the user control at run time to populate the radiobutton list and textbox.The problem is that even tough each of the UserControls load, only the first one populates its textboxes/radiobutton lists.p.s I am not using a reader purposefully because there are...

How to create custom properties for aspx page which should refelect in design time properties window itself.( as like as custom server control).
Hi. I need to create the custom properties for aspx page itself where those custom properties should refelet in the properties window at the design time as like as other custom server controls. I tried pageBase class which will have cusom properties for page and inherited that pageBase to my aspx page . But its refelecting the code  behind file not in design time. I need to accss those aspx page custom properties at the design time itself in properties window as like as other custom server control.I appriciate your help. [FYI: my scenerio is customer ...

Problem while try to set public property of user control at design time , Its happen due to UpdatePanel Control(Ajax)
Hi I have put my user control's content in Update Panel(To get Ajax Benefit) and I have register this User control in my page.  I have exposed one public property of user control in which I am trying set one textbox enable, As this property is public I am try to set its value from design time from my pagewhen I run this code its give me run time error Object Ref. not set for textbox while Public Property set its value.  If I Remove Update Panel from my user control its work properly kindly help me to solve this Problem.  //User Control Source File  <%@ Contr...

Use property value in custom control child control
Hello, I am creating a custom control and I have the following property:   <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String     Get       Dim s As String = CStr(ViewState("Text"))       If s Is Nothing Then         Return String.Empty       Else         Return s       End If     End Get     Set(ByVal Value As String)       ViewState("Tex...

Setting Property On User Control On Parent Control At Run Time
I have an ASPX page with a custom user control. I need to set the paramters at run-time, but the user control isn't getting the parameter set.Here's what I'm doing in the parent page:   //UserControl UC= (UserControl)Page.FindControl("UC");   UC.Attributes["Attribute1"] = Attribute1;My User Control has a public string class level variable called Attribute1.I also tried this:http://www.dotnetjunkies.com/Article/E1F97CE9-7834-46FA-BED9-866F720AB013.dcikHowever, that caused a System.StackOverflowException.  I know that this is caused by something being called ...

user control
testUserControl.ascx  <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testUserControl.ascx.cs" Inherits="testUserControl.testUserControl" %> <asp:Label ID="Label1" runat="server" Text="User control label"></asp:Label> <br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />  testUserControl.ascx.csusing ...

Design-time persistence of child control properties within custom control
(using asp.net 1.1) I have created a dll web custom control. It contains child server controls, such as dropdownlist and textbox. For each child server control I have added a property in the custom control class which exposes the child control itself with all its properties. For instance, I have a dropdown property in the custom control class which 'gets' the child control dropdownlist(set is unnecessary because once I have 'gotten' the control I can set its properties) and thus exposes the child control and all its properties in the designer properties window of the ap...

Set the property of a server control inside a user control inside a Master Page
How do you set the property(ForeColor) of a server control(lnkInquiryReport2) located in a user control (LeftNavMain1) within a Master Page (default.master)? On the user control, expose a property of type color and bind this to the forecolor for the hyperlink control [keep some default value]. On your master page expose the user control as a property. On your content page, access the uc via the master's prop and the forecolor prop via the uc's prop and set it. Instead of exposing the uc from the master, you can also find the uc on the master - cast it to the correct type and then access th...

Design-time problem with TableStyle property of custom control
Hi all,I've been writing custom menu control (inherited from HierarchicalDataBoundControl). Everything (both run-time and design-time) worked just fine, until I added new property like this:         private TableStyle tableStyle;        [Category("Styles")]        [PersistenceMode(PersistenceMode.InnerProperty)]        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]        public virtual TableStyle Tabl...

Custom Server Control Design Time Property Shows "Object reference not set to an instance of an object"
The property "ReferenceValue" from my code below keeps showing an error in the properties window as above. The control however functions perfectly otherwise. 1 Imports System 2 Imports System.Web 3 Imports System.Web.UI 4 Imports System.Web.UI.WebControls 5 Imports Capr.Web.UI.ControlInterfaces 6 7 8 Namespace Controls 9 10 Public Class WMSTextBox 11 Inherits System.Web.UI.WebControls.TextBox 12 Implements ICaprBaseControl 13 14 Public Sub New() 15 End Sub 16 17 Public P...

How Do I: (1) Show an image in the design time view of my control? (2) Have a controls property be a drop down list at design time?
I'm currently writing my first custom server control and could use a couple of pointers:First off I would like to have my control show an image in its design time view rather than the generic grey box with text in it.Secondly I have a property for my control that can be changed at design time via the properties menu.... at the moment the designer types in a value under the controls properties... I would like a drop down list displayed in the properties with all the available options in it, Any pointers in these directions would be greatly appreciated.    Cheers. ...

Using a user control in a custom server control.
I've created a custom server control and am trying to add a user control to the rendering of the server control.  Is this possible?  If so, hints as to how this is done would be GREATLY appreciated!  Thanks in advance for considering an answer to this question. Wendi Use the LoadControl method. For example:   Controls.Add(LoadControl("~/controls/login.ascx"))Steven BeyRecursion: see Recursion My server control renders a table with x number of rows.  I want to add a user control to each row of the table, last column.  I do not know how ...

Getting value of a property in Parent User control from a Child user control
I have a ChildUserControl that is loaded inside a ParentUserControl. The host page loads ParentUserControl.I would need to access properties in ParentUserControl from the ChildUserControl.Thanks for your time Here's some ideas: You can from the child access the parent and run findcontrol. child.parent.findcontroL("indyanguy1") child.parent.parent.findcontrol("indyanguy1") The trick is when you get your findcontrol working to cast the result to the object type your looking forHere I'm looking for a label so I cast to label then I can use the .Text property.Y...

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

Web resources about - Adding a property to a user control, setting property at design time, then using value in control markup - asp.net.custom-server-controls

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Thousands of dollars of property stolen from Port Augusta home during Christmas break-in - AdelaideNow ...
DEFENCE medals and unique jewellery are among thousands of dollars of property stolen during a break-in at a Port Augusta home over Christmas. ...

Facebook's Mark Zuckerberg faces trial over Silicon Valley property deal
... broke a promise to introduce him to Silicon Valley's elite. Facebook boss Mark Zuckerberg is headed toward a trial after all as the property ...

Canberra's rental yields on the rise, despite sluggish property market
Canberra has experienced the lowest annual shift in rental prices in Australia over the past decade.

Mount Isa Police crackdown nets 20 people over property theft - The Courier-Mail Search Search
ABOUT 20 people have been charged, including 17 juveniles, after a series of break and enters and thefts in Mount Isa.

Bomb squad called to Qld property
TWO men have been charged after police found explosives at a property in Helidon.

Warning of 'unfair' process unheeded as government forges ahead with property resumptions
Private property is being forcibly resumed by the NSW government for major infrastructure projects such as WestConnex using a system it was warned ...

Property damage, power out in Waroona fire
At least one old property has been destroyed by intense fires that hit Waroona and Preston Beach. Vision courtesy of 9 News Perth.

Spiking property assessments may leave thousands without Home Owner Grant
A spike in property assessments in Metro Vancouver means thousands no longer qualify for the Home Owner Grant, unless the provincial government ...

Resources last updated: 1/15/2016 6:23:28 AM