Sharepoint Forum

 
Home » Forum » Sharepoint       Ask a questionRSS Feeds

SPS 2003 Custom Web Part with an .ascx control

  Asked By: Jamie Baker         Date: Apr 01, 2006      Category: Sharepoint      Views: 291
 

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
CreateChildControls:

UserTDAP =
CType(Page.LoadControl("/controls/DTCControls/TDAP.ascx"),
DTCControls.TDAP)
AddHandler UserTDAP.grdData.SortCommand, AddressOf
UserTDAP.grdData_SortCommand
Controls.Add(UserTDAP)

Here's the source code for RenderWebPart:

Me.EnsureChildControls()
Dim Asr As AppSettingsReader = New AppSettingsReader
Dim strOrg As String = CStr(Asr.GetValue("TDAPOrg",
GetType(System.String)))
UserTDAP.Organization = strOrg
UserTDAP.RetrieveByOrgName()
' Render the control
UserTDAP.RenderControl(output)

Tagged:                  

 

3 Answers Found

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

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

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

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, 2006       

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.


Your Answer
  • Answer should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].