By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,983 Members | 1,627 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,983 IT Pros & Developers. It's quick & easy.

Adding selectable ASP options to Custom Web Controls

P: n/a
Hello,

One thing I am looking to do is to create a couple of different custom
Web Controls that can give me added options when specifying them
in an ASP.NET page. For example:

<asp:RadioButtonList id=RadioButtonList1 runat="server">
<asp:ListItem myvalue1="x" myvalue2="y">Item 1</asp:ListItem>
<asp:ListItem myvalue1="a" myvalue2="b">Item 2</asp:ListItem>
<asp:ListItem myvalue1="g" myvalue2="h">Item 3</asp:ListItem>
</asp:RadioButtonList>

What I did was to create a custom Web Control and created get/set statements
for myvalue1 and myvalue2. I actually placed the value of the DataTextField
into a HashTable so the value I was setting could be stored and retrieved
depending on the listItem and/or what was selected. I am having problems
getting
this to work. Am I concentrating on the right area to get this all to work?

Thanks,
Peter

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Peter,

I think you're going to run into trouble because you're trying to make HTML
do something that it wasn't intended to do. Rather than mess with illegal
attributes, how about just separating the values with a pipe (|) or other
character and then parsing the selected value.

Here's some samble code in VB (VS 2005). Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub RadioButtonList1_SelectedIndexChanged _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myvalue As String()
myvalue = Split(RadioButtonList1.SelectedItem.Value, "|")
Label1.Text = "myvalue1=" & myvalue(0) & " : myvalue2=" & myvalue(1)
End Sub
</script>

<html>
<head runat="server">
<title>Multi List</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList id="RadioButtonList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedI ndexChanged">
<asp:ListItem Value="x|y">Item 1</asp:ListItem>
<asp:ListItem Value="a|b">Item 2</asp:ListItem>
<asp:ListItem Value="g|h">Item 3</asp:ListItem>
</asp:RadioButtonList><br />
&nbsp;<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>

"Peter" <sp**@nospamerino.com> wrote in message
news:pP******************************@comcast.com. ..
Hello,

One thing I am looking to do is to create a couple of different custom
Web Controls that can give me added options when specifying them
in an ASP.NET page. For example:

<asp:RadioButtonList id=RadioButtonList1 runat="server">
<asp:ListItem myvalue1="x" myvalue2="y">Item 1</asp:ListItem>
<asp:ListItem myvalue1="a" myvalue2="b">Item 2</asp:ListItem>
<asp:ListItem myvalue1="g" myvalue2="h">Item 3</asp:ListItem>
</asp:RadioButtonList>

What I did was to create a custom Web Control and created get/set
statements
for myvalue1 and myvalue2. I actually placed the value of the
DataTextField
into a HashTable so the value I was setting could be stored and retrieved
depending on the listItem and/or what was selected. I am having problems
getting
this to work. Am I concentrating on the right area to get this all to
work?

Thanks,
Peter

Nov 19 '05 #2

P: n/a
Thanks for very much for the reply Ken. Yes, I was originally thinking in
the
direction you mentioned but there are multiple components where I need to
store these dual values and one of them is a textbox. However now that
I know this is not doable I will go with the strategy of populating the
DataValueField.
As for the textboxes I can use the tooltip field. I can write a function to
sort
it all out for me.

BTW, the reason I wanted the more elegant solution is that I was hoping once
I got this all together was to have non-technical type people to build these
scripts
as needed because they seem to make almost daily changes. However if I spell
it
out for them it hopefully won't be too bad...

Thanks,
Peter
"Ken Cox [Microsoft MVP]" <BA**********@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Peter,

I think you're going to run into trouble because you're trying to make
HTML do something that it wasn't intended to do. Rather than mess with
illegal attributes, how about just separating the values with a pipe (|)
or other character and then parsing the selected value.

Here's some samble code in VB (VS 2005). Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub RadioButtonList1_SelectedIndexChanged _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myvalue As String()
myvalue = Split(RadioButtonList1.SelectedItem.Value, "|")
Label1.Text = "myvalue1=" & myvalue(0) & " : myvalue2=" &
myvalue(1)
End Sub
</script>

<html>
<head runat="server">
<title>Multi List</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList id="RadioButtonList1" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="RadioButtonList1_SelectedI ndexChanged">
<asp:ListItem Value="x|y">Item 1</asp:ListItem>
<asp:ListItem Value="a|b">Item 2</asp:ListItem>
<asp:ListItem Value="g|h">Item 3</asp:ListItem>
</asp:RadioButtonList><br />
&nbsp;<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>

"Peter" <sp**@nospamerino.com> wrote in message
news:pP******************************@comcast.com. ..
Hello,

One thing I am looking to do is to create a couple of different custom
Web Controls that can give me added options when specifying them
in an ASP.NET page. For example:

<asp:RadioButtonList id=RadioButtonList1 runat="server">
<asp:ListItem myvalue1="x" myvalue2="y">Item 1</asp:ListItem>
<asp:ListItem myvalue1="a" myvalue2="b">Item 2</asp:ListItem>
<asp:ListItem myvalue1="g" myvalue2="h">Item 3</asp:ListItem>
</asp:RadioButtonList>

What I did was to create a custom Web Control and created get/set
statements
for myvalue1 and myvalue2. I actually placed the value of the
DataTextField
into a HashTable so the value I was setting could be stored and retrieved
depending on the listItem and/or what was selected. I am having problems
getting
this to work. Am I concentrating on the right area to get this all to
work?

Thanks,
Peter


Nov 19 '05 #3

P: n/a
Hi Peter,

Another approach would be to use a set of parallel hidden fields to hold the
extra values. You would have to match them up to the visible field in some
way, perhaps through a naming convention.

Ken

"Peter" <sp**@nospamerino.com> wrote in message
news:f-******************************@comcast.com...
Thanks for very much for the reply Ken. Yes, I was originally thinking in
the
direction you mentioned but there are multiple components where I need to
store these dual values and one of them is a textbox. However now that
I know this is not doable I will go with the strategy of populating the
DataValueField.
As for the textboxes I can use the tooltip field. I can write a function
to sort
it all out for me.

BTW, the reason I wanted the more elegant solution is that I was hoping
once
I got this all together was to have non-technical type people to build
these scripts
as needed because they seem to make almost daily changes. However if I
spell it
out for them it hopefully won't be too bad...

Thanks,
Peter

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.