zoukankan      html  css  js  c++  java
  • 为继承masterpage的页面设置defaultbutton和defaultfocus

    一个普通的aspx页面,我们可以很容易地为其设置设置defaultbutton和defaultfocus,具体如下:

    .aspx:

     <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click"></asp:Button>
                <asp:Button ID="SubmitButton" Text="Submit" runat="server" OnClick="SubmitButton_Click">
                </asp:Button>
            </div>
        </form>

    .cs:

     protected void Page_Load(object sender, EventArgs e)
        {
            this.Form.DefaultButton = SubmitButton.ID ;
            this.Form.DefaultFocus = TextBox1.ID;
        }

    但是如果我们的页面是继承于一个masterpage的,形如:

    .aspx:

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click"></asp:Button>
        <asp:Button ID="SubmitButton" Text="Submit" runat="server" OnClick="SubmitButton_Click"></asp:Button>
    </asp:Content>

    .cs: 

    protected void Page_Load(object sender, EventArgs e)
        {
            this.Form.DefaultButton = SubmitButton.ID;
            this.Form.DefaultFocus = TextBox1.ClientID;
        }

     

    在执行时就会提示出现“The DefaultButton of 'form1' must be the ID of a control of type IButtonControl. ”的异常;解决的办法是:在这个页面,用一个panel控件把textbox, button包起来,比如:

    .aspx:

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:panel id="panel" runat="server">
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click"></asp:Button>
            <asp:Button ID="SubmitButton" Text="Submit" runat="server" OnClick="SubmitButton_Click"></asp:Button>
        </asp:panel>
    </asp:Content>

    .cs:

    protected void Page_Load(object sender, EventArgs e)
        {
            panel.DefaultButton  = SubmitButton.ID;
            this.Form.DefaultFocus = TextBox1.ClientID;
        }

  • 相关阅读:
    剑指Offer-用两个栈实现队列
    剑指Offer-从尾到头打印链表
    滑动门技术实现
    解决keil5中文注释乱码方法
    faker数据填充详解
    redis在微博与微信等互联网应用笔记
    JDBC插入中文数据出现?号地解决问题
    idea配置less自动编译
    idea使用Vue的v-bind,v-on报错
    idea 代码部分格式化
  • 原文地址:https://www.cnblogs.com/lovewife/p/1396359.html
Copyright © 2011-2022 走看看