Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SPS 2003 Custom Web Part with an .ascx control

  Asked By: Jamie    Date: Apr 01    Category: Sharepoint    Views: 1256

I have a custom 2003 web part which contains a .ascx
control. This .ascx control has a datagrid (grdData),
a button (btnDisplay) and a label (lblText). The
datagrid has sort capability and when
grdData_SortCommand is triggered, the data sorts on
that column and text is displayed in lblText. Also,
when I click btnDisplay, text is displayed in lblText.

I test the .ascx control on a web form and it works as
advertised. When I incorporate the .ascx control into
the web part, the data for the grid retrieves fine,
but grdData_SortCommand never gets triggered. What's
strange is I can click on the button within the .ascx
control and it will fire that event.

Does anyone have a clue why grdData_SortCommand never
fires within the web part.

Here's the web part source code for

UserTDAP =
AddHandler UserTDAP.grdData.SortCommand, AddressOf

Here's the source code for RenderWebPart:

Dim Asr As AppSettingsReader = New AppSettingsReader
Dim strOrg As String = CStr(Asr.GetValue("TDAPOrg",
UserTDAP.Organization = strOrg
' Render the control



3 Answers Found

Answer #1    Answered By: Christop Mcfadden     Answered On: Apr 01

I just figured this out - I simply moved the code
that populates the data from RenderWebPart to
CreateChildControls. I was then able to sort the

Answer #2    Answered By: Lacey Daniels     Answered On: Apr 01

This is precisely what I was driving at with my question. All events
must be wired up in CreateChildControls or the events won't fire.

The only time I use RenderWebParts or the new WSS v3 RenderContents is
when a value is set programmatically during the dynamic creation of the
page and isn't available until that state of the page life cycle.

While on this point, please use RenderContents and not just Render when
overriding methods in WSS v3. So many blogs and even the VSeWSS get this
wrong. The client side IDs for your Web Part are not generated if you
override Render instead of RenderContents. While not immediately visible
to the naked eye, the client-side JavaScript that may need to manipulate
your Web Part will fail when you least expect it. It significantly
limits the Web Parts AJAX abilities too.

Answer #3    Answered By: Megan Martin     Answered On: Apr 01

How is the datagrid added to the user control  class?

Didn't find what you were looking for? Find more on SPS 2003 Custom Web Part with an .ascx control Or get search suggestion and latest updates.