0

以下に示すように、2つのラジオボタンがあります。

<asp:RadioButton runat="server" GroupName="ebrochType" Text="Select Type 1" TextAlign="Right" ID="rbtSelect1" OnCheckedChanged="sel1" AutoPostBack="true" />

<asp:RadioButton runat="server" GroupName="ebrochType" Text="Select Type 2" TextAlign="Right" ID="rbtSelect2" OnCheckedChanged="sel2" AutoPostBack="true"  />

これらのいずれかを選択すると、メニューバーなどのない新しいウィンドウでページを開く必要があります...

これはコードビハインドで可能ですか?

これを試しましたが、うまくいきませんでした (ページ/更新パネルを更新しただけです):

Sub sel1(sender As Object, e As EventArgs)

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "select1", "window.open('http://www.google.co.uk','','')", True)

End Sub
4

2 に答える 2

0

はい、キー「onclick」と値「javascript:window.open('your url',your parameters)」を使用して各ラジオ ボタンに属性を追加することにより、コード ビハインドから実行できます。

于 2011-07-19T09:45:14.383 に答える
0

これを行う「最新の」方法は、JQuery を使用することです。

<div>
    <h3>Individual Radiobuttons</h3>
    <asp:RadioButton runat="server" ID="rb1" Text="Apples" CssClass="rb" GroupName="individ" />
    <asp:RadioButton runat="server" ID="rb2" Text="Oranges" CssClass="rb" GroupName="individ" />
    <asp:RadioButton runat="server" ID="rb3" Text="Bananas" CssClass="rb" GroupName="individ" />
</div>


<div>
    <h3>RadiobuttonList</h3>

    <asp:RadioButtonList runat="server" ID="rbList1" CssClass="rbList1" >
        <asp:ListItem Text="Cats" Value="1" ></asp:ListItem>
        <asp:ListItem Text="Dogs" Value="2"></asp:ListItem>
        <asp:ListItem Text="Rabbits" Value="3"></asp:ListItem>
    </asp:RadioButtonList>
</div>

外部 Javascript ファイルを使用します。
<script type='text/javascript' language='Javascript' src="/path/to/jscript/Tom.js'></script>

  1. JQuery ファイルで、onclick または onchange イベントのイベント ハンドラーを定義します。

    $(document).ready(function () {

    $(".rb").change(function () {
        window.open('http://www.google.com/search?hl=en&btnG=Search&q=' + $(this).text());
    });
    
    $(".rbList1").change(function () {
        //With RadiobuttonLists, the JQuery is a little more convoluted - a glance
        //at the markup will reveal why.
        window.open('http://www.google.com/search?hl=en&btnG=Search&q=' + $('.rbList1 :checked').next().text(), 'WindowFromRadiobuttonList', 'width=300,height=600');
    
    });
    

    });

HTH。

于 2011-08-19T09:17:22.653 に答える