使用JavaScript来启用禁用文本框并根据检查单选按钮计算价格。让ASP.NET中继器设置一个动态名称
我遇到的问题是我使用radiobutton的groupname来查找正确的文本框,并在计算中使用它的值。当中继器从我的itemtemplate创建代码时,它不会使用超级参数来创建名称。
我在该项目的标记名称是: 名= '<%#DataBinder.Eval的(的Container.DataItem, “idtag_domain”)%>' 它创建的名称是NAME = “Repeater1 $ ctl02 $文本框” 藏汉作为我提供的名称标签。 对于单选按钮的名称变为 Repeater1 $ ctl01 $ sverigemotrasism isnted只是 sverigemotrasism 的是有没有办法从创建名字阻止它......或者我该如何规避?
这是我的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>
我的JavaScript干这种事!找出被点击的文本框。
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';
}
不幸的是这是我的源代码看起来像中继器已经创造了一切...... 中继数据后!
<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" />
这是什么意思:问题是,当中继器让它的自己的力量松动?我不知道你在那里想说什么。 –
可能重复的[ASP.NET INamingContainer - 可选的前缀](http://stackoverflow.com/questions/4461463/asp-net-inamingcontainer-optional-prefixes) – jrummell
你正在使用哪个框架版本? –