Im using a javascript to enable disable textboxes and to calculate a price based on what radiobutton is checked.
The problem I have is that I use the groupname of the radiobutton, to find the correct textbox, and use it’s value in the calculation. When the repeater creates the code from my itemtemplate it does not use the supllied arguments to create an name.
My name in the item tag is:
name='<%# DataBinder.Eval(Container.DataItem, “idtag_domain”) %>’
The name it creates is name=”Repeater1$ctl02$textbox” aswell as the name tag i supplied.
For the radiobuttons their name becomes
Repeater1$ctl01$sverigemotrasism
isnted of just
sverigemotrasism
Is there a way to stop it from creating names… or how do I circumvent that?
This is my itemtemplate
<ItemTemplate>
<asp:RadioButton id="RadioButton1" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="50" Text="Fri tillgång" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton2" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>'
Text="En artikel om dagen(30/mån)" value="25" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton3" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="0"
Text="Skriv antalet artiklar" onclick="enableTB(this.name, this.checked)" />
<br />
<asp:TextBox ID="textbox" runat="server" name='<%# DataBinder.Eval(Container.DataItem, "idtag_domain") %>' Enabled="false" Width="106px"
onkeyup="calculatePrice()" style="background-color:#eeeeee" ></asp:TextBox>
</ItemTemplate>
My javascript does this! To find out what textbox was clicked.
function enableTB(tbname, checked)
{
var textboxen = tbname;
document.getElementById(textboxen).disabled = !checked;
document.getElementById(textboxen).style.background = '#C4F8CC';
}
function disableTB(tbname)
{
var textboxen = tbname + 1;
document.getElementById(textboxen).disabled = true;
document.getElementById(textboxen).style.background = '#eeeeee';
}
Unfortunately this is what my source code looks like after the repeater has created everything…
Repeater data!
<table>
<input id="Repeater1_RadioButton1_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_0">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_0">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_0">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl01$textbox" type="text" id="Repeater1_textbox_0" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="sverigemotrasism" style="width:106px;background-color:#eeeeee" />
<tr>
<td>
</td>
</tr>
<input id="Repeater1_RadioButton1_1" type="radio" name="Repeater1$ctl02$handlaihop" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_1">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_1" type="radio" name="Repeater1$ctl02$handlaihop" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_1">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_1" type="radio" name="Repeater1$ctl02$handlaihop" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_1">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl02$textbox" type="text" id="Repeater1_textbox_1" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="handlaihop" style="width:106px;background-color:#eeeeee" />
If you’re using the framework 4.0 you could use static ids for your controls. Try setting
ClientIDMode = Static
If you use
nameproperty you should be usinggetElementsByNameinstead ofgetElementByIdProbably you want to set the textbox id instead of the name. Take into account thatidproperty must to be unique for each control.I’m not sure if
GroupNamewill be static using above suggested setting. It’s worth to test it, if doesn’t work, you could set theCssClassproperty with the same value and use it as key to search the textbox.