asp.net EditTemplate中的RegularExpressionValidator

kfgdxczn  于 2023-08-08  发布在  .NET
关注(0)|答案(1)|浏览(94)

我有abc.aspx如下

<asp:content id="Content" ContentPlaceHolderID="cpContent" runat="server">

        <style type="text/css">
                .textbox-align-center {
                  display: flex;
                  text-align: center;
                }
        </style>
    
<asp:Panel ID="pnlPresentation" runat="server" Width="105%" ScrollBars="Auto">
        <asp:GridView ID="gridPresentation" runat="server" AutoGenerateColumns="False" >
    

        
        <asp:TemplateField HeaderText="abc" ItemStyle-HorizontalAlign="Center">
                            <EditItemTemplate>
                                <asp:RegularExpressionValidator ID="regexValidatorABC" runat="server" ControlToValidate="txtABC_Edit"
                                    ValidationExpression="^[A-Z]{1,3}\d{0,4}$" 
                                    ErrorMessage="Please enter a valid input with minimum length 3, maximum length 7 (with 1-3 Capitals letters followed by 4 digits), and no spaces."
                                    ForeColor="Red" Font-Size="Small" CssClass="textbox-align-center">
                                </asp:RegularExpressionValidator>                        
                                <asp:TextBox ID="txtABC_Edit" runat="server" Text='<%# Eval("[26_ABC]") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblABC" runat="server" AutoPostBack="true" OnTextChanged="txtABC_TextChanged" 
                                    Text='<%# Eval("[26_ABC]")%>' Width="100%" />
                            </ItemTemplate>
         </asp:TemplateField>
        </asp:GridView>
                
</asp:Panel> 
</asp:content>

字符串
当我打开EditTemplate时,具有验证器的TexBox没有居中对齐。
如何将其对齐到中心?

wkyowqbh

wkyowqbh1#

我在RegularExpressionValidator中删除了CssClass,并添加了div,并将EditTemplate和TextBox放在其中。
更新的代码在这里

<asp:content id="Content" ContentPlaceHolderID="cpContent" runat="server">

        <style type="text/css">
                .textbox-align-center {
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  text-align: center;
                }
        </style>
    
<asp:Panel ID="pnlPresentation" runat="server" Width="105%" ScrollBars="Auto">
   <asp:GridView ID="gridPresentation" runat="server" AutoGenerateColumns="False" >
        <asp:TemplateField HeaderText="abc" ItemStyle-HorizontalAlign="Center">
        <EditItemTemplate>
           <div class="textbox-align-center">
             <asp:RegularExpressionValidator ID="regexValidatorABC" runat="server" ControlToValidate="txtABC_Edit"
                                    ValidationExpression="^[A-Z]{1,3}\d{0,4}$" 
                                    ErrorMessage="Please enter a valid input with minimum length 3, maximum length 7 (with 1-3 Capitals letters followed by 4 digits), and no spaces."
                                    ForeColor="Red" Font-Size="Small">
                                </asp:RegularExpressionValidator>                        
                                <asp:TextBox ID="txtABC_Edit" runat="server" Text='<%# Eval("[26_ABC]") %>'></asp:TextBox>
</div>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblABC" runat="server" AutoPostBack="true" OnTextChanged="txtABC_TextChanged" 
                                    Text='<%# Eval("[26_ABC]")%>' Width="100%" />
                            </ItemTemplate>
         </asp:TemplateField>
        </asp:GridView>
                
</asp:Panel> 
</asp:content>

字符串

相关问题