date and time control format - c#

I have used Ajax calender extender to display date in Date_Box and then numeric up down extenders to chose time...
Here is my code:
<td bgcolor="#969ECD">
<asp:TextBox ID="Date_Box" runat="server" Width="85px"></asp:TextBox>
<br />
<div style="height: 4px"></div>
<asp:TextBox ID="txtHour" runat="server" ></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="txtHour_NumericUpDownExtender"
runat="server" Enabled="True" Maximum="12" Minimum="1"
TargetControlID="txtHour" Width="70" >
</ajaxToolkit:NumericUpDownExtender>
<asp:TextBox ID="txtMinute" runat="server"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="txtMinute_NumericUpDownExtender"
runat="server" Enabled="True" Maximum="59" Minimum="1"
TargetControlID="txtMinute" Width="70" >
</ajaxToolkit:NumericUpDownExtender>
<asp:TextBox ID="txtDayPart" runat="server"></asp:TextBox>
<ajaxToolkit:NumericUpDownExtender ID="txtDayPart_NumericUpDownExtender"
runat="server" Enabled="True" RefValues="AM;PM" TargetControlID="txtDayPart" Width="70">
</ajaxToolkit:NumericUpDownExtender>
<asp:Button ID="Update" runat="server" Text="Update"
onclick="Update_Click1" />
<br />
</td>
</tr>
</table>
</div>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="Date_Box" PopupPosition="TopRight" >
</ajaxToolkit:CalendarExtender>
Now functionality wise the only problem is when i write something in the textbox other than the normal format and click the update button it lets me accept the values instead it should not let it write anything else other than the date format.. eg no alphabets in the textbox..
This i can still figure out, using some exception message...
but now the main problen is the look of the control. The numeric extender buttons are too big and the line format is not good, also there is lots of space between the three time textboxes... is there a way to make this look neat>>>
How can i solve the problem... any suggestions???!
here is the image link http://www.freeimagehosting.net/image.php?05945773e0.jpg
alt text

The easiest thing to do is to assign your numeric extenders a CssClass property, and use css to fix the layout issues.

You can use asp:RegularExpressionValidator to validate textbox contents:
http://msdn.microsoft.com/en-us/library/eahwtc9e.aspx
The documentation for NumericUpDown specifies you can use custom images for the updown buttons:
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/NumericUpDown/NumericUpDown.aspx

You may want to try the FilteredTextbox from the ajax control kit found here.
It will prevent typing into the box if they do not meet certain criteria.
Hope this helps
Tom

Related

HTML Required field not working as needed

In am using htm required="required" validation but it is not working properly as needed.
I have 2 button on single page and I want that on 1 button click it validate for textbox1 and on click of 2nd button it will validate for textbox2.
Please review attached image for more detail
You are looking for ValidationGroup. By giving a collection of Validators and a Button the same id, the corresponding button will only validate those fields.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1" ValidationGroup="group1"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox2" ValidationGroup="group1"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button Group 1" ValidationGroup="group1" />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox3" ValidationGroup="group2"></asp:RequiredFieldValidator>
<asp:Button ID="Button2" runat="server" Text="Button Group 2" ValidationGroup="group2" />
I don't think HTML does that natively (grouped validation).
If server-side is not an option, then you'll need to use some JavaScript.
I have found some inspiration in this answer for a related question (Triggering HTML5 Form Validation) : https://stackoverflow.com/a/39689115/370786
If you group each set of inputs that you want to validate together in a form (so you will have several forms), then you can trigger validation through Javascript. Then you can stop the form from posting. This can be done through Javascript - maybe it can be done in HTML but I'm not sure.
Then once everything has validated you will need to post the data to the server, using some Javascript. It might be as simple as just triggering the submit() method on a form element.

asp panel default button property is not working in ie for live application

I have a page having multiple buttons and search functionality.I have placed one button and textbox in a panel.After writing seach text if I hit Enter,it works well for all the browsers on local, but for live application this is not working in IE.
The html is:
<asp:Panel ID="pnlSearch" runat="server" CssClass="search" DefaultButton="btnSearch">
<h2>
Explore QualityStocks without logging in</h2>
<asp:TextBox ID="txtSearch" CssClass="txt" runat="server" ToolTip="Stock Ticker" ></asp:TextBox>
<asp:Button TabIndex="0" ID="btnSearch" runat="server" ClientIDMode="Static" CssClass="btn" OnClick="btnSearch_Click" />
</asp:Panel>
What am I missing to do?
Thanks in advance,
Priya

Submit by pressing enter asp.net

I am wondering why this, submitting on pressing enter, is only working on ie and not on google chrome...
This is the code I use actually :
<div class="TxtBox">
<asp:Panel ID="lepanel" runat="server" DefaultButton="Connect">
<asp:TextBox ID="TxtUserLogin" runat="server" TabIndex="1" Text="login" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="TxtUserLogin"></asp:RequiredFieldValidator>
<asp:TextBox ID="UserPass" runat="server" TabIndex="2" Text="password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="UserPass"></asp:RequiredFieldValidator>
<asp:LinkButton ID="Connect" runat="server" OnClick="Connect_Click" TabIndex="3">connect</asp:LinkButton>
</asp:Panel>
<asp:Label ID="MsgError" runat="server" />
<div class="ForgottenPass">
forgotten password ?
</div>
<div class="RememberMe">
<asp:CheckBox runat="server" ID="chkBoxRemember" />
stay signed in
</div>
</div>
A LinkButton renders as a HTML anchor tag.
HTML anchor tags do not submit HTML forms. Therefore when you click Enter, this is not actioning any submit button.
A Button renders as HTML <input type="submit" />
An ImageButton renders as HTML <input type="image" />
These elements will both action your form.
Therefore changing LinkButton to Button or ImageButton is the best solution.
Using a LinkButton is also bad for users who do not have javascript enabled.
This is a known issue, when you add as default a link button (actually a link) and not a real button then there is a case that is not trigger properly.
So if you change it to real button you make it work.

maskedextender and calenderextender in asp.net

I am new person in asp.net. I have one text box and one calender image button in my asp.net application. I use the masked extender to display date in the textbox like yyyy-mm--dd. Also i use the calender extender for the purpose of clicking image button it will show the date in the textbox. I use the following code.
<asp:ImageButton ID="imgdatefrom" runat="server"
ImageUrl="~/images/calendar.jpeg" Height="19px" Width="20px" />
<asp:Label ID="lblTo" runat="server" Text="End Date"
ForeColor="Black" Font-Size="Small"></asp:Label>
<asp:Label ID="enddateval" runat="server" ForeColor="Red" Text="*"></asp:Label>
<asp:CalendarExtender ID="txtDateFrom_CalendarExtender" runat="server" TargetControlID="txtDateFrom" Format="yyyy-MM-dd" PopupButtonID="imgdatefrom"
TodaysDateFormat="yyyy d, MMMM">
</asp:CalendarExtender>
While I executing that code and selecting date by clicking image button the selected date will not displayed in the textbox. Can anyone know how to solve the problem.
Thank you
Instead of MaskedExtender you just use standard TextBox Control. It will work.

problem with asp.net validationcontrol

I have a textbox and I have set required validationcontrol on it on click of a button.
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" runat="server" ControlToValidate="name" ErrorMessage="Name is required" Display="Dynamic" />
</td>
but the problem is when I am clicking on modify shared webpart and when I click on APPLY or OK button it is not saving as my form is empty . and I can't put
CausesValidation="false" on that button as this button is by default in sharepoint.
Any idea how to resolve this...?
You can use the ValidationGroup property to group all the Validators and validation fields together.
Yes using the ValidationGroup tag will help to relate the controls in a single form and will tell the submit button which fields are associated. Also make sure you have a ValidationSummary control on the page with the same ValidationGroup value. Also consider adding an InitialValue="" onto the TextBox control.
<asp:ValidationSummary ID="vs1" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" runat="server" ValidationGroup="Form" HeaderText="There were problems with your submission:" />
<asp:TextBox runat="server" ID="name" Width="120"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvname" ValidationGroup="Form" runat="server" ControlToValidate="name" InitialValue="" ErrorMessage="Name is required" Display="Dynamic" />
<asp:LinkButton ID="lnkSubmit" Text="Submit" OnClick="lnkSubmit_Click" ValidationGroup="Form" runat="server"></asp:LinkButton>

Categories

Resources