开发者

debug a CompareValidator (ASP.NET)

开发者 https://www.devze.com 2023-01-28 22:02 出处:网络
What is the best way to debug a CompareValidator that always f开发者_JS百科ails the validation?Is there any way to see what the values are that it\'s comparing to maybe get a clue as to what\'s going

What is the best way to debug a CompareValidator that always f开发者_JS百科ails the validation? Is there any way to see what the values are that it's comparing to maybe get a clue as to what's going wrong?


Use Firebug to debug the javascript that .Net inserts


If you are not familiar with the other debugging methods, easiest way for you may be utilizing the Response.Write calls to print the values in your button event to see if they are equal to each other:

Response.Write(TextBox1.Text.ToString().Trim());
Response.Write(TextBox2.Text.ToString().Trim());
Response.End();

Update

For simplicity, I will use CompareValidator to check a data type.

You probably have something similar to the following in your ASPX (client side) code:

<asp:TextBox ID="txtTest" runat="server" />

<asp:CompareValidator ID="cvTest" runat="server"
ControlToValidate="txtTest" 
Operator="DataTypeCheck" Type="Date" 
Display="Dynamic" ErrorMessage="Incorrect format!" />

<asp:Button ID="btnTest" Text="Test Compare Validator" 
onclick="btnTest_Click" runat="server" />

In your codebehind (server side), put the following in your btnTest_Click event to see the value that is entered in txtTest:

Response.Write(txtTest.Text.ToString().Trim()); 
Response.End(); 

But keep in mind that there more robust debugging utilities that VS offers. This is just a quick-and-dirty way for your purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号