【问题标题】:Opening new window on radiobutton selected with .net在使用 .net 选择的单选按钮上打开新窗口
【发布时间】:2011-10-08 07:59:42
【问题描述】:

我有 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

【问题讨论】:

    标签: javascript asp.net vb.net new-window


    【解决方案1】:

    是的,您可以从后面的代码中做到这一点,方法是为每个单选按钮添加一个属性,键为“onclick”,值为“javascript:window.open('your url',your parameters)”。

    【讨论】:

      【解决方案2】:

      执行此操作的“现代”方式是使用 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 文件:
      &lt;script type='text/javascript' language='Javascript' src="/path/to/jscript/Tom.js'&gt;&lt;/script&gt;

      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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-13
        • 2015-09-09
        • 1970-01-01
        相关资源
        最近更新 更多