一个页面上有多个radiobutton,某一个被选中时,页面下面将显示隐藏的panel,现在想实现点击radiobutton时,页面跳转到所显示的panel上面,就是将panel在页面中间。
因为页面内容较多,如果没有跳转,只能通过下拉才能看到新显示出来的panel的内容。

解决方案 »

  1.   

    如果是winform窗体,可以试试 this.ScrollControlIntoView,滚动到你的控件
      

  2.   

    webform有个智能导航SmartNavigationPage.SmartNavigation = true;
      

  3.   

    使用js找到panel的位置,脚本进行document.body.scrollTop=panel的offsetTop
      

  4.   

    <a href="#ct1">跳转到1</a> 
    <a href="#ct2">跳转到2</a>
    <br>
    <div id="ct1" style="height:1000px;">1</div>
    <div id="ct2">2</div>
      

  5.   

    很简单
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.SmartNavigation = true;
    }
    试试啊,不行就用脚本吧。
      

  6.   

    实现方法很多,就看你的需求了‘下面是一个例子
    <%@ Page Language="C#" Debug="true" %><%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
      protected void Page_Load(object sender, EventArgs e)
      {
      }  protected void RadioButtonX_CheckedChanged(object sender, EventArgs e)
      {
        RadioButton r = sender as RadioButton;
        if (r.ID == "RadioButton1")
        {
          Panel2.Visible = false;
          Panel1.Visible = true;
          Page.ClientScript.RegisterStartupScript(Page.GetType(), "js", "scrollTo('" + Panel1.ClientID + "')", true);
        }
        else if (r.ID == "RadioButton2")
        {
          Panel1.Visible = false;
          Panel2.Visible = true;
          Page.ClientScript.RegisterStartupScript(Page.GetType(), "js", "scrollTo('" + Panel2.ClientID + "')", true);
        }
      }
        </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <script type="text/javascript">
        function scrollTo(divid) {
          d = document.getElementById(divid);
          if (document.documentElement)
            document.documentElement.scrollTop = d.offsetTop;
          else
            document.body.scrollTop = d.offsetTop;
        }
      </script>
    </head>
    <body>
      <form id="form1" runat="server">
      <asp:RadioButton ID="RadioButton1" AutoPostBack="true" runat="server" GroupName="A" OnCheckedChanged="RadioButtonX_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" AutoPostBack="true" runat="server" GroupName="A" OnCheckedChanged="RadioButtonX_CheckedChanged" />
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <p>
        x</p>
      <asp:Panel ID="Panel1" runat="server" Visible="false">
        <div style="border: 2px solid red; height: 200px">内容11111111111111</div>
      </asp:Panel>
      <asp:Panel ID="Panel2" runat="server" Visible="false">
        <div style="border: 2px solid red; height: 200px">内容222222222222</div>
      </asp:Panel>
      </form>
    </body>
    </html>
      

  7.   

    一般的做法就是把pannel显示到点击位置的下面。