How do I make a Custom Property in my Custom Control into a Bindable Property

I've got a custom control in ASP.NET 2.0.  I want to bind one of its properties to data, but even though I specify the [ Bindable(true) ], before the property, the only property that shows up in the Data Bindings dialog is "visible".

 

This is my code for the Custom Control:

public partial class Offers_SearchTemplates_OfferSearchButton : System.Web.UI.UserControl

{

[Bindable(true)]

public virtual string OfferUID

{

get

{

object objTitle = ViewState["OfferUID"];

if (objTitle == null)

return string.Empty;

return (string)objTitle;

}

set

{

ViewState["OfferUID"] = value;

}

}

 

And this is where i need it to bind (its within a GridView):

<asp:TemplateField HeaderText="Show Offer" SortExpression="OfferID">

<ItemTemplate>

<uc1:OfferSearchButton ID="OfferSearchButton1" runat="server" OfferUID='<%# Eval("OfferID") %>' />

</ItemTemplate>

</asp:TemplateField>

0
bentidy
10/27/2006 12:06:36 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

9 Replies
916 Views

Similar Articles

[PageSpeed] 15
Get it on Google Play
Get it on Apple App Store

0
aspuser2004
11/1/2006 6:17:32 PM

I have already looked at that post and attempted everything stated. But still no joy.

 

This is where i bind the property:

<

asp:TemplateField HeaderText="Show Offer" SortExpression="OfferID">

<ItemTemplate>

<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("OfferID") %>' />

<uc1:OfferSearchButton ID="OfferSearchButton1" runat="server" OfferUID='<%# Eval("OfferID") %>' />

</ItemTemplate>

</asp:TemplateField>

NB. The HiddenField Value binds successfully however my custom OfferSearchButton OfferUID DOES NOT.

 

Here is the code where i attempt to make the OfferUID  property bindable:

[

Bindable(true)]

[

Category("Data")]

[

Localizable(true)]

public string OfferUID

{

get

{

object objTitle = ViewState["OfferUID"];

if (objTitle == null)

return string.Empty;

return (string)objTitle;

}

set

{

ViewState[

"OfferUID"] = value;

}

}

0
bentidy
11/3/2006 10:13:25 AM

I have already looked at that post and attempted everything stated. But still no joy.

 

This is where i bind the property:

<

asp:TemplateField HeaderText="Show Offer" SortExpression="OfferID">

<ItemTemplate>

<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("OfferID") %>' />

<uc1:OfferSearchButton ID="OfferSearchButton1" runat="server" OfferUID='<%# Eval("OfferID") %>' />

</ItemTemplate>

</asp:TemplateField>

NB. The HiddenField Value binds successfully however my custom OfferSearchButton OfferUID DOES NOT.

 

Here is the code where i attempt to make the OfferUID  property bindable:

[

Bindable(true)]

[

Category("Data")]

[

Localizable(true)]

public string OfferUID

{

get

{

object objTitle = ViewState["OfferUID"];

if (objTitle == null)

return string.Empty;

return (string)objTitle;

}

set

{

ViewState[

"OfferUID"] = value;

}

}

0
bentidy
11/3/2006 10:13:31 AM
Use Bind("OfferId") instead of Eval("OfferId").
0
aspuser2004
11/4/2006 3:06:03 AM

still no joy unfortunately.

 

the reason i am using eval instead of bind is that i only need the offerid to be readonly.

0
bentidy
11/8/2006 4:10:27 PM

It works fine in my project if I use Bind; it does not work with Eval. Did you try with Bind?

0
aspuser2004
11/9/2006 3:52:08 PM
aspuser2004:

It works fine in my project if I use Bind; it does not work with Eval. Did you try with Bind?

 

hi i have tried both but not working with me ..

tell me whats wrong with me

 

Heres the Controls Code..... (Im just trying its not actual project.. its just crap project)

private string _Val;

[

Browsable(true),

Bindable(true, BindingDirection.TwoWay),

Category("DataBind"),

DefaultValue("Default Value"),

DisplayName("MyValue"), EditorBrowsable( EditorBrowsableState.Always)]

public string Val

{

get { return _Val; }

set { _Val = value; }

}

 

protected void Page_Load(object sender, EventArgs e)

{

theText.Text = _Val;

}

 

 

heres the Default.aspx page code..

 

<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#336666"

BorderStyle="Double" BorderWidth="3px" CellPadding="4" DataKeyField="ID" DataSourceID="ObjectDataSource1"

GridLines="Horizontal" Width="310px">

<FooterStyle BackColor="White" ForeColor="#333333" />

<SelectedItemStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />

<ItemTemplate>

CardType:

<asp:Label ID="CardTypeLabel" runat="server" Text='<%# Eval("CardType") %>'></asp:Label><br />

<uc1:WebUserControl ID="WebUserControl1" runat="server" Val ='<%# Bind("FullName") %>' />

<br />

</ItemTemplate>

<ItemStyle BackColor="White" ForeColor="#333333" />

<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />

</asp:DataList>
Asif Ashraf
-
MCAD.Net, MCP
0
hackrogenius
5/5/2007 2:53:23 PM

hi

 IT IS WORKING with using Bind ... im sorry there was my mistak

 i have chagned the code like this

___________________

private

string _Val;

[

Browsable(true),

Bindable(true, BindingDirection.TwoWay),

Category("DataBind"),

EditorBrowsable

( EditorBrowsableState.Always)]

public string Val

{

get { return _Val; }

set { _Val = value;

theText.Text = _Val;

}

}

__________________________

 

it is working

 

THANX


Asif Ashraf
-
MCAD.Net, MCP
0
hackrogenius
5/5/2007 3:03:47 PM

hi .. ther is no EDIT post button... :( im messing with new posts ... anyhow

 "Eval" is also working .... with my previous code ... see last post ...

take care bye


Asif Ashraf
-
MCAD.Net, MCP
0
hackrogenius
5/5/2007 3:27:04 PM
Reply:

Similar Artilces:

adding custom properties to a custom server control
1.  I want to add a public property to a custom server control.  the property is called Search Type and the possible choices that will appear in the properties window from the asp.net page would be client, provider, vendor and service.  I want this property to function much like the border style property works for an asp.net button. 2.  My second question would be how do I add a section to the properties window?  What i mean is for this custom server control, i want to add a section called Search Features much like the appearance or behavior sections for an asp.net ...

custom property style for a custom server control
Can I add a proerty for style on my asp .net custom server control, seems to be one for everything else. Or do you have to go do one style at a time: backgroundColor, Font, etc....

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 ...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom controls with properties exposed in Dropdown or like Microsoft control properties
I need to create a custom control. For this control I want to expose some properties which I want to set from a XML/ from a Enum class. I want user to select the appropriate property from the dropdown to configure the control. (i.e. like we set AllowSorting property for Gridview and user can select just true or false from drop down)  So could anybody please help me finding a sample for such custom control? Hi There, Below is a simplae example of custom control which allow you to pick property via enum and booleancontrol: public partial class Sample_Control_WebUserControl2 : ...

Custom control with custom property not working properly
 Hi.I decided to implement a mechanism of Role Based Access Control using Azman and enhanced controls. I'll give you an example:[ControlBuilder(typeof(SecuredControlBuilder))]    public class SecureLinkButton : LinkButton    {        [        Category("General"),        DefaultValue("*"),        Description("The roles for which the control is visible.")     &nbs...

Custom server control with databound property failing to rebuild controls...
Hi, I've written a custom server control (radiobuttonlist) which has a property that is populated by a databound parent control (ie the value is passed through when the parent control is data bound). The custom server control creates it's contents based on the value that is passed. This works ok on the first creation as I use the Render method to populate the control, but when a command (save) is called on the parent control, the render method is not called and the custom control doesn't populate. I've tried many different ways to do what I need to do but all attem...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

Custom Control with both properties and child controls
I'm trying to write a custom web control which would like like that: <test:MyControl runat="server" id="myControl">   <SomeProperties>       <Item1>Item1</Item1>       <Item2>Item2</Item2>   </SomeProperties>     <Contents>       <asp:ListBox ID="ListBox2" runat="server"></asp:ListBox>         <!-- other child controls -->    </Contents></test:MyCon...

Property is not setting in custom control property
hi ,         I am adding an image control programmatically in a webpartzone which is adding successfully but the properties i am setting in image control are not setting .following is the code that i am using .the code 'img.ImageUrl = "~/images/atlas_title.jpg"     do not set the property in it.Dim webmgr As WebPartManager = WebPartManager.GetCurrentWebPartManager(Me)Dim img As New Web.UI.WebControls.Imageimg.ID = "Img"'img.ImageUrl = "~/images/atlas_title.jpg"     ...

How do I set the value of a custom property of a custom control in code-behind?
Perhaps I'm going about this the wrong way entirely, and I'm actually asking the wrong question... so here's what I would like to do: I have CustomControlB embedded in CustomControlA... CustomControlB has a custom property of "PublisherID" which I have created like this: private string _publisherid;public string PublisherID{     get     {          return _publisherid;     }     set     {     &nbs...

Web resources about - How do I make a Custom Property in my Custom Control into a Bindable Property - 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 ...

Confusion reigns as short-term rentals through Airbnb carry high cost for property owners
Mary&nbsp;Banfield was opening up her Surry Hills terrace to short-term stays. Then the council fee arrived.

'Big swing': Property investor loans plunge in October
The steam is clearly coming out of the housing market, thanks to a sharp decline in the level of investor lending.

China stocks rise, led by property shares - DailyTelegraph Search Search
CHINA stocks have climbed, led by property and resources shares, amid signs that insurers are scrambling for stakes in real estate majors and ...

China stocks rise, led by property shares
CHINA stocks have climbed, led by property and resources shares, amid signs that insurers are scrambling for stakes in real estate majors and ...

Basics key to selling Perth property, says new report - PerthNow Search Search
HOMES with water views might net a million-dollar return, but practical features such as a double lockup garage and a short commute to work make ...

Chinese demand for Aussie property drops as much as 15%, McGrath says
Chinese demand for Australian homes has dropped as much as 15 per cent from a year earlier as China's stocks tumbled and the economy slowed, ...

Men face court after $30,000 worth of suspected stolen property seized in Griffith
Two men are set to face the ACT Magistrates Court on Saturday morning in relation to stolen property and burglary charges.

Tribune Media Puts Third Property on the Auction Block
... to look very different. Tribune Media announced today that it has engaged the firm of Jones Lang LaSalle to find a buyer for the 25-acre property: ...

Resources last updated: 12/13/2015 7:24:47 AM