Unable to use Custom Control within a datagrid control

I have a datagrid and a template field to look like this

<

asp:TemplateField>

<ItemTemplate>

<customControl:Display runat="server" Description='<%#DataBinder.Eval(Container.DataItem,"Description")%>' />

<asp:Label ID="mylabel" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ReportID")%>' />

</ItemTemplate>

</asp:TemplateField>

My custom control has a property called "Description" which basically is nothing but the value for a label in that control. Now, in the above code, the asp label control correctly displays the text, but my custom control property is not set?

Any reasons ?

Thanks. Please let me know if you know the answer to this. I am trying to set the property of the custom control in the Page_LOad event of the custom control

 

0
cvajre
12/6/2006 11:42:28 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
752 Views

Similar Articles

[PageSpeed] 29

Hi, cvajre:

Would u plz show the code about the usercontrol especially about the 'Description' property.




Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
0
rexlin
12/7/2006 1:32:36 AM

Here is the code for the user control

public partial class UserControls: System.Web.UI.UserControl
{
        private string reportDescription;

 public string ReportDescription
    {
        get { return reportDescription; }
        set { reportDescription = value; }
    }

protected void Page_Load(object sender, EventArgs e)
    {

 lblReportDescription.Text = ReportDescription;

}

}

0
cvajre
12/7/2006 4:13:23 AM

Hi , cvajre:

The code you gave me has the property of ReportDescription instead of the Description you have mentioned above. 




Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
0
rexlin
12/7/2006 6:33:00 AM

Hi, cvajre:

Put this statement into OnPreRender event  of UserControl

lblReportDescription.Text = ReportDescription;




Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support

This posting is provided "AS IS" with on warranties, and confers no rights.
0
rexlin
12/7/2006 7:11:43 AM

Well that had the same name sorry. What I mean is both have the same name in my code. When I tried to just create only the required part, i might have put the wrong name. BUt you can assume both have the same name.

Thanks again.

0
cvajre
12/7/2006 3:54:27 PM

When are you trying to access the value of your custom control property? It is obviously being set at some point or you label would not display the text. However, because web pages are stateless, if you are trying to access the value of your control in a callback/postback at some point and your grid is not being rebuilt, the property is lost.

Try using the viewstate when saving control properties you want to access later:

public partial class UserControls: System.Web.UI.UserControl
{
  public string ReportDescription
  {
    get 
    {
      string report = (string)ViewState["ReportDescription"];
      if (string == null)
        return string.Empty;

      return report;
    }
    set { ViewState["ReportDescription"] = value; }
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    lblReportDescription.Text = ReportDescription;
  }
}
 
Hope that helps.
 
0
pramsperger
12/7/2006 8:18:15 PM
Reply:

Similar Artilces:

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

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

ajax.net controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an ajax.net control like the accordion....

Error using the PopupControlExtender control when referencing controls that are contained within another control...
I'm running into an issue when using the PopupControlExtender control. It appears the if the TargetControlID or control you are targeting is inside another ASP.NET control you can not access the control b/c the ID of the control when the page renders is differnt. It appears that you also can not use the <%# control.UniqueID %> method b/c the PopupControlExtender does not support DataBinding. An example of my problem...I have a wizard control. Inside that wizard control is a textbox called TextBox1. I want to add a popup calendar to that textbox by using the PopupControlExtender contro...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Custom DataGrid control in user control
Hi there, I have created a custom datagrid control which i reference within a user control and it's corresponding code behind page. The problem I am encountering is that when I click on the paging buttons in the datagrid no event is fired, however if I reference the same control from a page everything works fine. I'm not sure where I am going wrong and would be greatful for any help that can be offered. I have not posted the code here as there is quite a lot although should anyone feel that it would be helpful in them coming to a solution I would be more than willing to do so. Cheer...

Custom Control using Wzard Control
Hi I have been building a page with a wizard in it, no problems there. The thing is that the wizard control will need to be added in numerous loactions within an aplication. So I would like to make a control of the wizard then use that, like an old fashioned #include I guess. If someone can tell me the best way to do this and steer me in the right direction I'll appreciate it. Thanks! you dont need to use old fashioned way to do this, If you want to include a user control on a page at design time the you should put following line on the top of ur aspx page. <%@ Register Src...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control to Custom Control communication using event delegate mech.
I have a custom control “AddressPicker” that displays dynamic address information of a user. BY dynamic I mean based on the database call it checks how may addresses a user has and it displays it. There is a “Use this Address” button at the bottom of each address information which is generated dynamically too as a part of CreateChildControl. If a user click on this button I need to pass this information to another custom control namely “AddressConsumer” which in turn uses this information for further processing.My Controls are inherited WebCOntrol,INamingContainer I am using the event deleg...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

How to place a DataGrid Control with in a DataGrid Control
Hi, I want to place a DataGrid control in a DataGrid control can any one plz tell me the procedure to place the control Thanks in Advance Krisamigo <!---<asp:DataGrid ID=dg_List runat=server><Columns><asp:TemplateColumn><ItemTemplate><asp:DataGrid ID=dg_List2 Runat=server></asp:DataGrid> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> ---> Hardik Joshi...

Page and Control Flashing Using AJAX Control Toolkit Controls
Page and Control Flashing Using AJAX Control Toolkit Controls I'm using IE7 and the ASP.NET AJAX Control Toolkit.  I'm using two controls -- Accordion and CollapsiblePanelExtender.  I'm actually using 2 CollapsiblePanelExtenders, and the Accordion control is inside one of the panels for the CollapsiblePanelExtender (see the code below). The problem I'm seeing is that when I click an Accordion pane to open/close it or click the CollapsiblePanelExtender panel to open/close the panels, the controls and page flash while the animation is in progess.  Everything el...

Use Ajax controls within web control
Is there any example that show how to write a custom web control (one that doesn't have aspx) and use Ajax controls ? I have a user control consisting of a panel the modalpopupextender. I have a copy of the aspx and .cs file in all the sites.  I want to turn it into a control so I can re-use it. How can I achive it? Hi Thanhhuynh, Basically, you can drag it into your customer control without doing any other special settings. Ajax Control Toolkits work depend on ScriptManager or ToolkitScriptManager. Please make sure that the ScriptManager should be located before the e...

Web resources about - Unable to use Custom Control within a datagrid control - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/17/2015 8:50:57 PM