HTML输入类型按钮:无效属性

发布于 2025-01-29 03:37:32 字数 286 浏览 4 评论 0原文

在一个旧的ASP.NET Web表单应用程序中,我在页面的ASPX代码中收到了此警告:

属性'FullName'不是元素“输入”的有效属性,

为什么以这种方式写入?

还有一种解决方法吗?

in an old ASP.NET Web Forms application I got this warning in the aspx code of a page:

Attribute 'fullname' is not a valid attribute for element 'input'

Why was written in this way?

And there is a way to resolve it?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肤浅与狂妄 2025-02-05 03:37:32

您只会收到警告。一个简单的问题是,开发人员刚刚构成了一个属性,并以某种价值推翻。这是合法的,我经常这样做是为了说一个标准的文本框。

因此,例如,我可以将5或10个文本框和控件放置在DIV内,这样的说明:

<div id="EditRecord" runat="server" style="float:left;display: normal;border:solid 2px;padding:5px">
  <div style="float:left" class="iForm">
    <label>HotelName</label>
    <asp:TextBox ID="txtHotel" runat="server" f="HOtelName" width="280" />  <br />
    <label>First Name</label>
    <asp:TextBox ID="tFN" runat="server" f="FirstName" Width="140" /> <br />
    <label>Last Name</label>
    <asp:TextBox ID="tLN" runat="server" f="LastName" Width="140" /> <br />
    <label>City</label>
    <asp:TextBox ID="tCity" runat="server" f="City" Width="140" /> <br />
    <label>Province</label><asp:TextBox ID="tProvince" runat="server" f="Province" Width="75"></asp:TextBox> <br />
  </div>
  etc. etc. etc.

请注意,我想定义哪个数据库列以“填写”上述控件。

因此,我有一个带有数据行的例程。

        Call fLoader(EditRecord, rstData.Rows(0))

以上例程查找具有“ F = DataColum”的任何控件,并为我填写控件。

所以,我明白了:

”“在此处输入图像描述”

换句话说,我的自定义“ F”属性使我可以从数据库中获取数据并填写网页 - 而无需每次编写新代码。 (而且我有一个反常的例程 - 将所有控件写入f =“一些数据列”回到数据库中。使用这个简单的概念,然后我可以将任何网页读取/从数据库中读取/写入数据 - 和不必一遍又一遍地编写相同的代码,我得到了一个整个CRUD系统,并且通过添加一个“构成”属性的简单概念来实现,该属性定义了要使用的数据库

。 按钮添加一些自定义值。

 <asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
         <asp:Button ID="cmdView" runat="server" Text="Button"     
             OnClick="cmdView_Click"
             ProductID = '<%# Eval("ProductID") %>'
             CustomerID = '<%# Eval("CustomerID") %>'                 
             />

即使在网格视图中为一个

Protected Sub cmdView_Click(sender As Object, e As EventArgs)

    Dim btn As Button = sender

    Debug.Print(btn.Attributes("CustomerID").ToString())
    Debug.Print(btn.Attributes("ProductID").ToString())

您可以在vs中被抑制,但是我经常提到的措施, 构成一些属性,在大多数情况下,该按钮是合法

的 一般规则忽略了警告。那些自定义或“构成”属性。在大多数情况下,您会收到警告,但其他情况下,这并不是什么大不了的问题。当然,您确实必须很贴心,因为在大多数情况下,这种自定义属性没有自动视图状态,并且它们的价值无法正确地持续到往返(后背包和页面返回)。但是,对于上述示例之类的表达式或值,它不是问题。

You only get a warning. The simple issue is that the developer just made up a attribute, and shoved in some value. this is legal, and I often do this for say a standard text box.

so, I might for example place 5 or 10 text boxes and controls inside of a div, say like this:

<div id="EditRecord" runat="server" style="float:left;display: normal;border:solid 2px;padding:5px">
  <div style="float:left" class="iForm">
    <label>HotelName</label>
    <asp:TextBox ID="txtHotel" runat="server" f="HOtelName" width="280" />  <br />
    <label>First Name</label>
    <asp:TextBox ID="tFN" runat="server" f="FirstName" Width="140" /> <br />
    <label>Last Name</label>
    <asp:TextBox ID="tLN" runat="server" f="LastName" Width="140" /> <br />
    <label>City</label>
    <asp:TextBox ID="tCity" runat="server" f="City" Width="140" /> <br />
    <label>Province</label><asp:TextBox ID="tProvince" runat="server" f="Province" Width="75"></asp:TextBox> <br />
  </div>
  etc. etc. etc.

Note in above, I wanted to define what data base column for a routine to "fill out" the above controls.

So, I have a routine I call with a data row.

        Call fLoader(EditRecord, rstData.Rows(0))

the above routine looks for any control with a "f=datacolum", and fills out the controls for me.

So, I get this:

enter image description here

In other words, my custom "f" attribute allows me to pull data from a database, and fill out the web page - and without having to write new code each time. (and I have a reverse routine - writes out all controls with f="some data column" back to the database. With this simple concept, then I am able to have any web page read/write data to/from the database - and not have to write that same code over and over. In effect, I get a whole crud system, and all achieved by a simple concept of adding a "made up" attribute "f" that defines the data base column to use.

So, you can in VS have that warning suppressed, but I as noted OFTEN make and add some custom values. Even for a button in a grid view, you might have this:

 <asp:Repeater ID="Repeater1" runat="server">
     <ItemTemplate>
         <asp:Button ID="cmdView" runat="server" Text="Button"     
             OnClick="cmdView_Click"
             ProductID = '<%# Eval("ProductID") %>'
             CustomerID = '<%# Eval("CustomerID") %>'                 
             />

And then in code behind, you have this:

Protected Sub cmdView_Click(sender As Object, e As EventArgs)

    Dim btn As Button = sender

    Debug.Print(btn.Attributes("CustomerID").ToString())
    Debug.Print(btn.Attributes("ProductID").ToString())

So, we often just make up some attribute, and it is legal to do so in most cases.

So, that button - say dropped into a grid view now can pass values to the button click - even values not displayed in the gridview.

So, you can just as a general rule ignore the warning. It is not super common, but a lot of developers often will add and make up their own attributes, and client side code (JavaScript) or even code behind as above shows is then free to use the values in those custom, or "made up" attributes. In most cases, you get a warning, but other then that, it not a huge deal nor issue. You of course do have to be carful, since such custom attributes in most cases don't have automatic view state, and their values will not persist correctly for a round trip (post-back, and page return). However, for expressions or values such as above example, then its not a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文