具有“n”多个属性的ASP.Net用户控件(ASP.Net user control with “n” multiple properties)

编程入门 行业动态 更新时间:2024-10-27 09:42:46
具有“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

本文发布于:2023-08-03 16:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   控件   属性   用户   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!