Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Custom Server Control Property Won't Set

Reply
Thread Tools

Custom Server Control Property Won't Set

 
 
Joe
Guest
Posts: n/a
 
      01-15-2004
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:ControlTypeDropDown id="ddControl" runat="server"
DefaultValue='<%#DataBinder.Eval(Container.DataIte m,
"controlTypeId")%>' /><Br>
</ItemTemplate>
</asp:Repeater>

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

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using scPortal.Components;
using System.Web.Caching;
using System.Web.UI.WebControls;
using System.Collections;

namespace app.Controls
{

/// <summary>
/// A server control to display the dropdown of Control Types. Will
be
/// displayed programatically in a repeater.
/// </summary>
public class ControlTypeDropDown :
System.Web.UI.WebControls.DropDownList
{

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

public ControlTypeDropDown() : base(){}


protected override void OnInit(System.EventArgs e)
{

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

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



}



protected override void RenderContents(System.Web.UI.HtmlTextWriter
writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.FindByValue(DefaultValue).Selected=true ;
}

base.RenderContents(writer);



}

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if(DefaultValue != null && DefaultValue != "")
{
base.Items.FindByValue(DefaultValue).Selected=true ;
}

base.Render(writer);
}

protected override void OnLoad(System.EventArgs e)
{
if(base.EnableViewState)
base.DataBind();

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




public override void DataBind()
{
SortedList ht;
if(HttpContext.Current.Application["ControlTypeDropDown"]==null)
{
TS s = new TS();
ht = s.GetFormControls();

HttpContext.Current.Application.Add("ControlTypeDr opDown", ht);
}
else
{

ht = (SortedList)HttpContext.Current.Application["ControlTypeDropDown"];
}

base.DataSource = ht;
base.DataTextField = "value";
base.DataValueField = "key";
base.DataBind();

}

}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set server control property in markup using server side variable, even just a constant, is that possible? Ryan Liu ASP .Net 0 02-21-2009 08:25 PM
Custom Control : One custom property to array of controls anon ASP .Net Web Controls 0 01-15-2005 11:32 AM
Keep custom property-value in custom rendered control Rob Joosen ASP .Net Building Controls 0 05-12-2004 11:56 AM
Custom Server Control Property Won't Set Joe ASP .Net 0 01-19-2004 03:32 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments