SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Two of the same controls on the same page, but half working...

rated by 0 users
This post has 17 Replies | 2 Followers

Top 10 Contributor
Posts 2,872

 icelava wrote:
I placed one or two of the Paging controls into a bare page, giving them fictitious number of items and page size, and just by clicking on the number "1" link button, it computes to page 5. Hmmm I think it may be easier to use Community Server's Pager control instead.....

I don't understand your statement. Even if it is easier to use Community Server's Pager control, I still would like to find out why the phenominal is happening

Best Regards, Kit Kai, MVP (SharePoint Portal Server)

Top 10 Contributor
Posts 2,260
 kitkai wrote:
So how do I add html tags in between those controls that i add to the control collections?
Something to this effect (not complete refactor yet):

        protected override void Render(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);

            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
            writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
            writer.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
           
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td); // First column Td
            writer.AddAttribute(HtmlTextWriterAttribute.Align, "left");
            writer.Write("Page " + this.CurrentPage.ToString() + " of " + this.TotalPages.ToString());
            writer.Write(" (" + this.TotalRecords.ToString() + " items)");
            writer.RenderEndTag(); // First column Td

            writer.RenderBeginTag(HtmlTextWriterTag.Td); // Second column Td
            this.phPreviousPaging.RenderControl(writer);
            this.litCurrentPage.RenderControl(writer);
            this.phNextPaging.RenderControl(writer);
            writer.RenderEndTag(); // Second column Td

            writer.RenderEndTag(); // Tr
            writer.RenderEndTag(); // Table
        } // Render()

At first I made the page index start from 1, but later, I think datagrid's currentpageindex starts from 0 right? So I change it to start from 0, to standardise.
There needs to be provision to +1 whenever displayed in the HTML output. After all, end users are not used to starting with 0 for pages.

NoPreviousPage and NoNextPage is used to determine how many previous pages you want to show and how many next pages you want to show.
This is the part that has got me thinking - essentially how many LinkButtons to create will depend on the restoration of the ViewState (where the values are stored), but those LinkButtons also have to be created in CreateChildControls() in order for ViewState to be restored to them (if any), and event wire-up. Does this look like a Catch-22? I think I need to study how other controls with dynamically rendered child controls deal with this.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 10 Contributor
Posts 2,260
 icelava wrote:
protected override void Render(HtmlTextWriter writer)
I made an ignorant mistake - as a derived WebControl, RenderContents() should be overriden instead. Render() is a method of the baser Control class, and WebControl already overrides that to make use of RenderContents().

Additional overrides can be for the RenderBeginTag() and RenderEndTag() to customise the outer tag(s) for the control.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Page 2 of 2 (18 items) < Previous 1 2 | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems