I think this problem is probably a simple solution.
Im trying to use Validation Summary control, when i run the page and enter invalid input i get the error summmary (fine) but when i try to rectify the error by entering correct info the page wont run and the summary stays (even though the Validation Control message goes.)
Thanks
<asp:RegularExpressionValidator ID="regexStns" runat="server"
ControlToValidate="txtStones"
ErrorMessage="Weight (Stns) Must be one or two number characters."
ValidationExpression="/d/d?"></asp:RegularExpressionValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtPounds" ErrorMessage="RegularExpressionValidator"
ValidationExpression="\d\d?"></asp:RegularExpressionValidator>
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
That is the normal behavior of the ValidationSummary control.
Related
I have two ValidationSummary controls on one page:
<asp:ValidationSummary ForeColor="Red" Style="margin-left: 1.5%" ID="ValidationSummary"
runat="server"/>
<asp:ValidationSummary ForeColor="Red" Style="margin-left: 1.5%" runat="server"
ValidationGroup="vgOnScreen" />
These are both triggered by one button. Now my problem is, when there in an error for each control, it is displayed with an extra line in between which is inconsistent with the look of the application.
This is what the display looks like:
•This is my first error
•This is my second error
Does anyone know how to get rid of the extra line between two validation summary controls?
Apologies in advance, for what may be a newbie question. (new to asp.net, coding in VB, zero knowledge of best controls). Please respect that I am not interested in AJAX controls, or using MVC and trying to minimise javascript. What I need to do is very simple in terms of technology.
I am developing a form that allows users to Edit database data. I have chosen to use FormView so that I can format it like a legacy vba app. I am able to set the data source to my database table and the values from the database successfully show up if I allow VWD to automatically format the control. I can edit everything in the database using this form as well.
However, the boss hates having to type dates.
I haven't been able to find a datepicker control with a datasource feature that works like the text boxes that are automatically built in formview (with a bind to a datasource feature). So, I am assuming none exist. I need some assurances that what I think I need to do is the right way.
Instead of using the FormView control's datasource via the front-end automagical stuff, I should instead
place one of these datapicker controls that simply combine calendar with a text box for all date fields in the formview (no disrespect to those who built them, just can't believe they are not more feature-rich, this seems so needed giving the number of datepickers available)
declare my data source in Page_Load and load all the controls if they have existing data utilising FindControl
use Data_Bound block to retrieve the selected values from each control utilising FindControl and build a dynamic SQL string for Update
declare and update my database using one of the code behind blocks, perhaps in the DataBound
Am I on the right track? I have no experience to be confident in my assumption.
and please, if there is an easier way, I'll take it, but I have to make it "pretty".
And suggestions for controls of any sort are welcomed.
---Further into my issue
Here is some code to prove I've actually tried to resolve this...
In my FormView code block I have:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="MASTERID_Action"
DataSourceID="srcAction">
<EditItemTemplate>
MASTERID_Action:
<asp:Label ID="MASTERID_ActionLabel1" runat="server"
Text='<%# Eval("MASTERID_Action") %>' />
<br />
Action_Description:
<asp:TextBox ID="Action_DescriptionTextBox" runat="server"
Text='<%# Bind("Action_Description") %>' />
<br />
Action_Target:
<asp:TextBox ID="Action_TargetTextBox" runat="server"
Text='<%# Bind("Action_Target") %>' />
<br />
Action_Captured:
<asp:TextBox ID="Action_CapturedTextBox" runat="server"
Text='<%# Bind("Action_Captured") %>' />
<br />
Action_Declined:
<asp:TextBox ID="Action_DeclinedTextBox" runat="server"
Text='<%# Bind("Action_Declined") %>' />
<br />
Action_AgreedDate:
<ewc:CalendarPopup ID="CalendarPopup1" runat="server" Culture="en-AU"
PostedDate="" SelectedDate='<%# Bind("Action_AgreedDate") %>'
SelectedValue="01/14/2013 08:47:54" UpperBoundDate="12/31/9999 23:59:59"
VisibleDate="01/14/2013 08:47:54" />
<br />
...
</EditItemTemplate>
My database holds this Action_AgreedDate as nullable.
When I view the ItemTemplate (in the browser) the date shows up as 0.000 (because its a text field and bound to Action_AgreedDate, no error occurs) and when I click Edit to go to the EditItemTemplate I get this error:
Conversion from type 'DBNull' to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Date' is not valid.
Source Error:
Line 95:
Line 96: Action_AgreedDate:
Line 97: '
Line 99: SelectedValue="01/14/2013 08:47:54" UpperBoundDate="12/31/9999 23:59:59"
I can easily translate this into "the control found a null field and doesn't know what to do with it"; problem is, I don't know what to do. I have checked the properties of the field (the CalendarPOP field to see if there is a setting for handling nulls and nothing is obvious to me. I'm currently trying to find further documentation on the control online. (I've contacted eWorld and hope they will be able to respond.)
I should also add that if I request a record that already has an Action_AgreedDate I get no errors because there is a value present in the database for the control to display.
I think the best way for you to do this would be to use jQuery and jQuery UI, which has a date picker, which can be attached to a regular ASP.NET TextBox in your FormView. So if you had FormView code that looks something like this for example:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1">
<EditItemTemplate>
id:
<asp:Label ID="idLabel1" runat="server" Text='<%# Eval("solution_id") %>' />
<br />
date_modified:
<asp:TextBox ID="date_modifiedTextBox" runat="server" Text='<%# Bind("date_modified") %>' />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("solution_id") %>' />
<br />
date_modified:
<asp:Label ID="date_modifiedLabel" runat="server" Text='<%# Bind("date_modified") %>' />
</ItemTemplate>
</asp:FormView>
You could run something like this using jQuery UI to get a datepicker on the date_modified text box:
$('[id$=date_modifiedTextBox]').datepicker()
The $('[id$=date_modifiedTextBox]') part is necessary to select the ASP.NET control using jQuery, if it were just a normal element you could just use $('.className') or $('#id') or something like that. Hope this helps.
Problem solved.
I ran across an article on 4GuysFromRolla.com about the RJS POP Calendar (http://preview.tinyurl.com/cerm9xv) and it ticked all the boxes. Successfully implemented it and, because the calendar is separate from the specified text box, it doesn't have to be bound ! It works very nicely. The 4GuysFromRolla save my bacon yet again...
i am using validation control of asp.net . i got 10 fields and i have field validators with each of them . Now I want to show error but using ValidationSummary but errors also appear with individual validators. cant i close the individual error messages?
have you add a validation group.
try like this
<asp:ValidationSummary ID="ValidationSummaryVerifyInfo"
ValidationGroup="Verify" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" />
<asp:RequiredFieldValidator ID="RFVEmail" runat="server"
ErrorMessage="Please enter Email Id." ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Verify" ControlToValidate="TextBoxEmail">*</asp:RequiredFieldValidator>
To hide the validators you can place them into one div with CSS style display: none.
What is the best way to debug a CompareValidator that always fails 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.
I'd like a way to both show an asterisk by an invalid field and show a verbose message in a validation summary. However, setting Display to "NONE" in the validation control suppresses any message that would appear next to the field to validate.
Is there a way to get this kind of hybrid function?
Yes.
Set the text property to "*" and the ErrorMessage property to the actual error message. Something like.
<asp:RequiredFieldValidator id="ValidateMyField" runat="server" text="*"
errormessage="Hey, you must really specify something"
controltovalidate="YourControl" />
For the display you can use display="Dynamic" to have the * only take up space on an actual error.
<asp:ValidationSummary ID="valSummary" runat="server" />
<asp:CustomValidator ID="valUserNameTaken" runat="server" ErrorMessage="User name is already used in this system, please choose another.">*</asp:CustomValidator>