Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2004, 03:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Using attributes in custom control

I have a control that I have created to display the details of a customer.
I intend the control to display differently based on a "DisplayMode" attribute set for the control.
I am using this conrol from within a datagrid three times.
Only one will **************** at once depending on whether the datagrid is in the item, edit or footer template.
The problem is the code to effect the display mode does not get executed.(setDisplay();).
I know the other code in the item pageload event is executes because the control correctly sets the sutomer name in the literal control.

Can anyone see what I am doing wrong here?

Another interesting thing is that if I try to set the Literal control value in the code behind it does not work
eg. LTCompanyName.Text = this.Attributes["CompanyName"];
But setting a variable to this value and then binding the variable to the control as I have done below does work.

Any help / suggestions would greatly appreciated.

The code for the datagrid column is:
Code:
        <asp:TemplateColumn SortExpression="CompanyName ASC" HeaderText="Company">
            <ItemStyle VerticalAlign="Top" HorizontalAlign="Left"></ItemStyle>
            <ItemTemplate>
                <uc1:Customer id="CustomerItem" DisplayMode="0" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
            </ItemTemplate>
            <EditItemTemplate>
                <uc1:Customer id="CustomerEdit" DisplayMode="1" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
            </EditItemTemplate>
            <FooterTemplate>
                <uc1:Customer id="CustomerAdd" DisplayMode="2" CompanyName='<%# DataBinder.Eval(Container.DataItem,"CompanyName")%>' CustomerID='<%# DataBinder.Eval(Container.DataItem,"CustomerID")%>' runat="server"/>
            </FooterTemplate>
        </asp:TemplateColumn>
The html code for the control is
Code:
<table cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class='DGItemMainInfo'>
            <asp:Literal id="LTCompanyName" text='<%# CompanyName%>' runat="server">
            </asp:Literal>

        </td>
    </tr>
    <tr>
        <td>
            <div id='CustomerID_<%# CustomerID%>'  style="visibility:hidden;display:none">
                <asp:Panel id="PNLItem" runat="server">Item Panel</asp:Panel>
            </div>
            <asp:Panel id="PNLEdit" runat="server">Edit Panel</asp:Panel>
            <asp:Panel id="PNLAdd" runat="server">Add Panel</asp:Panel>
        </td>
    </tr>
</table>
And the code behind is:

Code:
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put code to initialize the page here
            CompanyName = this.Attributes["CompanyName"];
            CustomerID = this.Attributes["CustomerID"];
            displayMode = (DisplayMode) int.Parse(this.Attributes["DisplayMode"]);
            setDisplay();
        }

        private void setDisplay()
        {
            PNLItem.Visible = false;
            PNLEdit.Visible = false;
            PNLAdd.Visible = false;

            switch(displayMode)
            {
                case DisplayMode.Item:
                    PNLItem.Visible = true;
                    break;
                case DisplayMode.Edit:
                    PNLEdit.Visible = true;
                    break;
                case DisplayMode.Add:
                    PNLAdd.Visible = true;
                    break;
            }
        }
======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old June 3rd, 2004, 03:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

MORE INFO:

It appears that the code to assign the attribute to the variable also does not work.
It appears that the form is binding directly to the attribute so none of the code behind is being executed.

This narrows down my wuestion to:

How do I get the code behind of a user control to execute in a datagrid.

Thanks again in advance.

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old June 7th, 2004, 09:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I was able to assign the attributes via the oncreated event of the datagrid lines by refereing to the control and accessing its properties.
This resolved my situation however I was still not able to predictively use the page load event of the user control.
I think this is related to the when the various controls are created given the various templates of the datagrid.

======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
how to control optional elements and attributes NEO1976 XSLT 5 September 4th, 2006 02:58 AM
Custom Compile-Time Attributes brrrdog General .NET 1 March 3rd, 2004 12:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.