Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameters (not properties) to a user control? 2

Status
Not open for further replies.

adam0101

Programmer
Jun 25, 2002
1,952
US
I thought it was possible to pass parameters to a user control, but I can't find any examples. Am I wrong about this? By parameters, I mean:
Code:
<uc1:MyControl id="MyControlId" runat="server">
  [b]<parameter name="MyFirstParameter" value="val1">
  <parameter name="MySecondParameter" value="val2">[/b]
</uc1:gridfilter>
Or something like that. I can't use properties because the name of the parameter will be dynamic. Is there a tutorial somewhere that can help me with this?

Thanks,

Adam
 
maybe u can use controls???

Imports System
Imports System.Collections
Imports System.Web
Imports System.Web.UI

NameSpace Hi
Public Class TagBuilder
Inherits ControlBuilder

Public Overrides function GetChildControlType(Tag as String, Attributes As IDictionary) as Type
if Tag.toLower()="item" then
return GetType(ControlItem)
end if
return nothing
end function

end class


<ControlBuilderAttribute(GetType(TagBuilder))> _
Public Class CustomControl
Inherits Control

Public Text as string
Public TextColor as string

Dim ControlList as new ArrayList()
Protected Overrides Sub AddParsedSubObject(obj as Object)
if (typeof obj is ControlItem) then
ControlList.add(obj)
end if
end sub
Protected Overrides Sub Render(Writer as HtmlTextWriter)
Writer.AddAttribute("Color",TextColor)
Writer.RenderBeginTag("font")
Writer.write(Text)
Writer.RenderEndTag()

Dim Ctrl as ControlItem
for each Ctrl in ControlList
Writer.AddAttribute("Color",Ctrl.Color)
Writer.RenderBeginTag("font")
Writer.write(Ctrl.Text)
Writer.RenderEndTag()
next
end sub
End Class

Public Class ControlItem
Inherits Control
Public Text as string
Public Color as string
Dim ControlList as new ArrayList()
Protected Overrides Sub AddParsedSubObject(obj as Object)
if (typeof obj is LiteralControl) then
if(obj.text)<>"" then
Text=obj.text
end if
end if
end sub
end class
End NameSpace



<Hi:CustomControl runat="server" Text="Hello" TextColor="red">
<item color="green">This is the goddamn text</item>
</Hi:CustomControl>


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top