自定义验证器中的控件名称 .NET 客户端验证
我有一个带有三列文本框的网格视图。它可以根据需要拥有任意多的行,但通常只有大约 5 行。每一行都需要进行验证。
我想创建一个客户端验证器,将 2 列相加,并将其与第三列进行比较,以检查用户是否正确输入了数据。
以防万一您想知道,这是规范的一部分,操作员必须输入第三列,而不是简单地在后面的代码中将前两列相加。这样做是为了确保操作员正确转录信息。
我正在尝试使用 .net 中的自定义验证器来创建此客户端验证。但我找不到将三个文本框的名称传递给它的方法。 我可以使用 ControlToValidate 参数为其提供目标控件名称,但如何传入其他两个控件 id ?
我正在寻找“正确”的方法来执行此操作,一种想法是在 JavaScript 中创建一个由 controltovalidate 名称引用的数组。
直流
I have a gridview with three columns of textboxes. It can have as many rows as necessary but its usually only about 5 rows. Each row needs to be validated.
I want to create a client side validator that sums 2 of the columns together and compares it with the third column to check that the user has entered the data correctly.
Just in case you are wondering, it's part of the spec that the operator must enter the third column rather than simply summing the two previous columns together in the code behind. This is done to ensure the operator is transcribing the information correctly.
I am trying to use the custom validator in .net to create this client side validation. but I can't find a way to pass to it the names of the three text boxes.
I can give it the target controls name using the ControlToValidate parameter, but how do I pass in the other two control id's ?
I am looking for the 'proper' way to do this, one thought is to create an array in javascript referenced by the controltovalidate's name.
DC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了这个问题。这不是一个优雅的解决方案,但它有效。
首先我将代码放入页面上的 div
然后我创建了一个 JavaScript 函数...
这是由每行的自定义验证器调用的我使用发送者的 controltovalidate 参数来获取名称
然后它是一个问题字符串操作来获取其他字段的名称。
一旦检索到,您就可以做您喜欢做的事情,在我的例子中,我添加并比较。如果出现错误,Isvalid 标志将被清除,并且消息将被修改以适应。
getmessage 函数是必需的,因为我更改消息以提供更有意义的错误消息
getmessage 函数保留原始消息的副本,因此如果用户多次犯错,则可以以其原始形式检索消息,否则第一次编辑消息时,我们会覆盖占位符 (#total#)。
直流
I solved the problem. not an elegant solution but it works.
first I placed the code into a div on the page
Then I created a JavaScript function...
This is called by the custom validator for each row I use the controltovalidate parameter of the sender to get the name
then its a matter of a bit of string manipulation to get the names of the other fields.
Once retrieved you can do what you like, in my case I add and compare. if there is an error the Isvalid flag is cleared and the message is modified to suit.
The getmessage function is required because I alter the message to give a more meaningful error message
The getmessage function keeps a copy of the original message so if the user makes a mistake more than once the message can be retrieved in its pristine form, other wise the first time we edit a message we overwrite the placeholder (#total#).
DC