473,563 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Server Control Property Won't Set

Joe
I am having a hard time with setting a property on a custom server
control that i am placing in a repeater. The control inherits from
DropDownList. The property is being set in the repeater using the
DataBinder.Eval method. I can write that value out to the screen,
however, it is not available to the control. I think it is a problem
with the databinding of the repeater making data available to the
custom control too late.

Below is a snippet of how the control is being setup in my aspx page.
After that is the code for my control. I've tried to set that
DefaultProperty in 2 different places but can't think of anything
else.

----------------------------------
ASPX
----------------------------------

<asp:repeater id=rpt DataSource="<%# dt%>" Runat="server">

<ItemTemplate >
<frmControl:Con trolTypeDropDow n id="ddControl" runat="server"
DefaultValue='< %#DataBinder.Ev al(Container.Da taItem,
"controlTypeId" )%>' /><Br>
</ItemTemplate>
</asp:Repeater>

----------------------------------
Server Control
----------------------------------

using System;
using System.Web;
using System.Data;
using System.Data.Sql Client;
using System.Web.Cach ing;
using System.Web.UI.W ebControls;
using System.Collecti ons;

namespace app.Controls
{

/// <summary>
/// A server control to display the dropdown of Control Types. Will
be
/// displayed programatically in a repeater.
/// </summary>
public class ControlTypeDrop Down :
System.Web.UI.W ebControls.Drop DownList
{

private string defaultValue;
public string DefaultValue
{
get{return defaultValue;}
set{defaultValu e=value;}
}

public ControlTypeDrop Down() : base(){}
protected override void OnInit(System.E ventArgs e)
{

if(base.EnableV iewState && !Page.IsPostBac k)
{
//If using ViewState, only DataBind the FIRST time the page is
loaded.
this.DataBind() ;

}
else if(!base.Enable ViewState && !Page.IsPostBac k)
{
//If not using ViewState, DataBind EVERY time the page is loaded.
//Setup();
this.DataBind() ;
}

}

protected override void RenderContents( System.Web.UI.H tmlTextWriter
writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.Find ByValue(Default Value).Selected =true;
}

base.RenderCont ents(writer);

}

protected override void Render(System.W eb.UI.HtmlTextW riter writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.Find ByValue(Default Value).Selected =true;
}

base.Render(wri ter);
}

protected override void OnLoad(System.E ventArgs e)
{
if(base.EnableV iewState)
base.DataBind() ;

base.Attributes .Add("onChange" , "openWin(this)" );
}


public override void DataBind()
{
SortedList ht;
if(HttpContext. Current.Applica tion["ControlTypeDro pDown"]==null)
{
TS s = new TS();
ht = s.GetFormContro ls();

HttpContext.Cur rent.Applicatio n.Add("ControlT ypeDropDown", ht);
}
else
{

ht = (SortedList)Htt pContext.Curren t.Application["ControlTypeDro pDown"];
}

base.DataSource = ht;
base.DataTextFi eld = "value";
base.DataValueF ield = "key";
base.DataBind() ;

}
}
}
Nov 18 '05 #1
0 1271

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

Similar topics

4
1906
by: Rudy | last post by:
Hello all, I'm sure there is, just can't figure it out. I have the RGB code and the color number. But the color doesn't exsist in Visual studio.net. Can I add this color to the system pallet it self, so I can add the custom color to fonts? I need to match as close as possible to the color I was given. Thanks Rudy
4
4760
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For...
2
1894
by: Andre | last post by:
I've set up a CustomValidator control which has both a client side and server side function associated with it. My server side function never seems to be called as long as I have the "EnableClientScript" property set to true. As soon as I set this property to false , my server side function is called and works fine. From reading the help, it...
7
2977
by: Shimon Sim | last post by:
I have a custom composite control I have following property
3
3176
by: cannontrodder | last post by:
I am displaying names and other details of my users in a Formview control by binding my custom business object to it. My custom object also has a property that is a collection of boolean values and I would like to show a checkboxlist within my formview to represent them. I just have no idea how to bind this collection to a list within the...
15
6491
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then...
0
1937
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in the ini on the client's PC. After the program has ended the control looks in a client side temp folder (specified by the ini file) for an image created...
5
1518
by: TS | last post by:
I have a custom textbox that i need to access a label's text property. the label and textbox are 2 separate controls that will be on my page. Inside my custom control i want to have access to this label's text. I was thinking of having a property on my textbox that was something like LabelControlID. the textbox could then do a .Findcontrol on...
4
2472
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user...
0
7659
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...
0
7580
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...
0
8103
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...
1
7634
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...
0
7945
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5481
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...
0
5208
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...
0
3634
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...
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.