具有“n”多个属性的ASP.Net用户控件(ASP.Net user control with “n” multiple properties)
我希望我的用户控件具有采用n个不同参数的功能。 n无意修复。 例如,有一次我将3个字符串传递给它,下一次12:
<mycompany:MyUC runat="server" ID="mctID" Para1="test1" Para2="test3" Para3="test4" Para4="test8" /> <mycompany:MyUC runat="server" ID="mctID" Para1="test1" Para2="test3" Para3="test4" Para4="test8" Para5="test1" Para6="test3" Para7="test4" Para8="test8" />如果没有事先定义属性,这可能吗?
I want my user control to have the functionality of taking n different parameters. n is not meant to be fix. For example one time I will pass 3 strings to it and next time 12:
<mycompany:MyUC runat="server" ID="mctID" Para1="test1" Para2="test3" Para3="test4" Para4="test8" /> <mycompany:MyUC runat="server" ID="mctID" Para1="test1" Para2="test3" Para3="test4" Para4="test8" Para5="test1" Para6="test3" Para7="test4" Para8="test8" />Is this possible without defining the properties in advance?
最满意答案
除非你用某种分隔符传递它,否则我认为这是不可能的:
MyProperty="Value1, Value2, Value3"然后在代码端用“,”拆分它。
但我认为最好只是在控件中有一个函数并传递值,例如作为字符串数组(VB.Net语法):
掌控之中:
Public Sub SetMyValues(values As String()) ' Store in viewstate or do what you need End Sub初始化控件时,可以从页面或任何需要的位置进行调用:
MyControl1.SetMyValues({"Value1", "Value2", "Value3"})I used another method to achieve my goal. The solution was to use the PersistenceMode attribute in my property together with my own class "SelectControl":
<PersistenceMode(PersistenceMode.InnerProperty)> _ Public Property SelectControls() As List(Of SelectControl) Get .... End Get Set(ByVal value As List(Of SelectControl)) ... End Set End Property <myCompany:QDirectEditAdapter runat="server" ID="deaContactsSupplier" EditControlID="grdContactsSupplier" EditControlKeyField="SSC_USR_ID_FK"> <SelectControls> <myCompany:SelectControl ControlID="cboUserSelection" ContainerID="pnlUserSelection" KeyField="USR_ID" ActivityColumns="USR_USERNAME, USR_NAME" /> <myCompany:SelectControl ControlID="qacProductSelection" ContainerID="pnlProductSelection" KeyField="NR" ActivityColumns="SSC_APPLICATION" /> </SelectControls> </myCompany:QDirectEditAdapter>更多推荐
<mycompany,test,电脑培训,计算机培训,IT培训"/> <meta name="descriptio
发布评论