0

JavaScriptを使用してテキストボックスを無効にし、チェックされているラジオボタンに基づいて価格を計算しています。

私が抱えている問題は、ラジオボタンのグループ名を使用して正しいテキストボックスを見つけ、その値を計算に使用することです。リピーターが私のitemtemplateからコードを作成するとき、名前を作成するために提供された引数を使用しません。

アイテムタグの私の名前は次のとおりです。name='<%#DataBinder.Eval(Container.DataItem、 "idtag_domain")%>'作成される名前は、name = "Repeater1 $ ctl02$textbox"と指定した名前タグです。 。ラジオボタンの場合、その名前はRepeater1 $ ctl01 $ sverigemotrasismになります。これは、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" />
4

1 に答える 1

1

フレームワーク4.0を使用している場合は、コントロールに静的IDを使用できます。ClientIDMode =Staticを設定してみてください

ただし、ID値を階層的にネストしたくない場合があります。代わりに、IDを設定した値にレンダリングするだけです。これを有効にするには、ClientIDMode = staticを使用できます。この場合、レンダリングされるIDは、コントロールのサーバー側で設定したものとまったく同じになります。

nameプロパティを使用する場合は、getElementsByName代わりに使用する必要がありgetElementById ます。おそらく、名前の代わりにテキストボックスIDを設定する必要があります。idプロパティは、コントロールごとに一意である必要があることを考慮に入れてください。

GroupName上記の推奨設定を使用して静的になるかどうかはわかりません。テストする価値があります。機能しない場合はCssClass、同じ値でプロパティを設定し、テキストボックスを検索するためのキーとして使用できます。

于 2012-08-27T18:29:05.677 に答える