Click to See Complete Forum and Search --> : Custom Controls


pki15
July 8th, 2003, 10:31 AM
Hi, I'm working on learning to design web parts for the Sharepoint Portal Server. Web parts are essentially ASP.NET custom controls. My question is that I want the web part to display information from a database. Can I use my custom control, and when overriding Render, add more ASP.NET code(to access the database). Maybe the code will make my question more clear:


Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages

< DefaultProperty("Text"), ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"), XmlRoot(Namespace:="TestWebPart")> _
Public Class MyWebPart
Inherits WebPart
Protected Overrides Sub RenderWebPart(ByVal Output As HtmlTextWriter)
Output.Write(SPEncode.HtmlEncode( _
'Can I have the ASP.NET Code in here to display a database??
))
End Sub

End Class

I'm new to ASP.NET, so bear with me if this is a dumb question. If I can't do the code this way, is there another way to accomplish what I want? Thanks

DSJ
July 8th, 2003, 10:42 AM
Looks to me like you already have most of it coded, is it not working?

pki15
July 8th, 2003, 10:47 AM
I was just unsure of whether or not the HtmlEncode function would accept more ASP.NET code. For Example:

HtmlEncode("<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDB" %>
<script language = "VB" runat="server">
etc...")


Is it legal to put more ASP.NET code inside this function?

pki15
July 8th, 2003, 10:51 AM
Sorry, i'll try again.

HtmlEncode("< %@ Import Namespace="System.Data" % >
< % Import Namespace= "System.Data.OleDb" % >
< script language = "VB" runat="server" >
etc...)

Just wondered if this was legal code, to encase more ASP.NET code inside the render overload.