views:

81

answers:

2

I have a custom .net control like this:

<myControl:control1 ID="dimDataSource" runat="server" SelectorType="red"
                    EnableViewState="False"  >
</myControl:control1>

I want to add a property that varies with the state of a standard html checkbox. (but if this can't be done, i'll add a .net checkbox)

So here's a checkbox:

<input type="checkbox" id="propertytoggle" >

I think the new tag should be something like this, but I can't get the syntax right:

<myControl:control1 ID="dimDataSource" runat="server" SelectorType="red"
                    EnableViewState="False" NewProperty="<% propertytoggle.checked %>"   >
</myControl:control1>

Is this possible, and if so, what's the right syntax?

adam

+1  A: 

You won't be able to propertytoggle.Checked unless propertytoggle is a .NET checkbox (which in your example, it isn't.)

You won't be able to get the value of the HTML checkbox until the page is posted back, then you have to check if the checkbox name (not ID) is present in the Form that was posted back. You could create a function in your code-behind file that returns whatever you need for your custom Control. Then you should be able to do:

NewProperty="<%=MyFunctionInCodeBehind() %>"
Andy Shellam
A: 

If you want the property to change when the checkbox changes, you will have to handle it in code behind. For initial setting, like you are trying to do in your example, I would try adding an = into the inline tags like so:

NewProperty="<%=propertytoggle.checked %>"
Jared
Andy is also correct. The checkbox should be and asp control.
Jared