move focus to another asp.net control after ajax toolkit calendar extender selection - asp.net

I am having trouble finding an answer to this problem.
What I am trying to do is this;
I have an asp.net (aspx) page that has two text boxes on it (among other controls) that have an Ajax Toolkit Calendar Extender on them. The first text box get focus and the calendar control appears and I am able to select a date just fine.
Here is my problem. After the date is selected for the first text box with the calendar control I want the second text box to automatically have the same date entered into it and the focus moved to a button (btnSearch) not the second text box.
I am using VB in code behind. I must not be wording my searches correctly because I can't seem to find anything close to solving this.
Does anyone have any ideas as to how this can be done? I am open to using JQuery if I have to but would prefer not to.
Thanks for any help in advance.
Note: There is no code to show because I can't find anything to try.
Update:
Here is the html I have:
<asp:TextBox runat="server" ID="txbDateStart" CssClass="form-control input-lg" ReadOnly="true" Visible="false" OnTextChanged="txbDateStart_TextChanged"/>
<cc1:CalendarExtender ID="CalendarExtender1" PopupButtonID="imgPopup" runat="server" TargetControlID="txbDateStart" Format="MM/dd/yyyy" PopupPosition="Right" />
<asp:TextBox runat="server" ID="txbDateEnd" CssClass="form-control input-lg" Visible="false" ToolTip="Click to change End Date" ReadOnly="true" />
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txbDateEnd" Format="MM/dd/yyyy" />

Related

.net ascx control not retaining value on postback (mojoPortal)

I'm making a custom module for mojoPortal CMS which needs to allow the client to add an affiliate into the database. As far as I can tell, this requires creating a .ascx file and then installing that using the administration toolbar in the Web interface to get it to a point where I can put it into a page, as http://www.mojoportal.com/hello-world-developer-quick-start.aspx.
The form is simple enough, but the values in the text boxes just stay empty when I submit, though the file upload works fine. The code:
<asp:Label ID="Label1" runat="server" Text="Company Name" AssociatedControlID="CompanyName">
</asp:Label>
<asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Company Description" AssociatedControlID="CompanyDescription"></asp:Label>
<asp:TextBox ID="CompanyDescription" TextMode="MultiLine" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Company Logo" AssociatedControlID="CompanyLogo"></asp:Label>
<asp:FileUpload ID="CompanyLogo" runat="server" />
<asp:Button ID="SubmitButton" runat="server" Text="Add Affiliate" />
EnableViewState for the page and the controls is enabled
The text box is not set to ReadOnly, and there is no funky JavaScript dynamically modifying elements (at least, I didn't set any).
I can work around this by using HTML elements, and get the values using Request.Form. The information is actually there, I can see it in the Request.Form, but I would have to get that by something like Request.Form[CompanyName.ClientId.Replace("_","$")] or Request.Form[6] which both seem very messy and IIRC aren't really the way things are supposed to roll in .NET. Besides, having worked until 3 last night, I really want to know what the answer is now!
Any thoughts anyone?
What I had done was not created a click event for the button, relying on the fact that it was posting to the server (like I would in PHP). Oops! When I added a click event, then the text boxes retained their value when I was within that method.

Is it possible to avoid rendering the error message from an ASP.Net validator control until the validator is evaluated as invalid?

Considering the fact that I was not able to find a single instance of someone else needing this functionality anywhere else, this might be an off the wall requirement. That said:
A website that I am working on uses several dozen different validator controls (everything from RequiredFieldValidaotrs to CustomValidators) throughout for form validation. As part of our Section 508 compliance, we have to support users who disable CSS, which is problematic because the validators render the error text to the page and use the CSS display property to hide it. When CSS is disabled all of the error messages are both visible and read by screen readers.
Short of using labels and postbacks to show and hide said labels, is there any known method for using ASP.Net validator controls with CSS disabled?
Use the Display="None" attribute on the FieldValidator control and a ValidationSummary tag to contain the messages.
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="TextBox1" /> <br />
<asp:TextBox runat="server" ID="TextBox2" /> <br />
<asp:Button runat="server" Text="Go" />
<div class="messages">
<asp:ValidationSummary id="summery1" runat="server"/>
</div>
<div>
<asp:Panel ID="Panel1" runat="server" >
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required Field Validator1 empty" ControlToValidate="TextBox1" Display="None" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Required Field Validator2 empty" ControlToValidate="TextBox2" Display="None" />
</asp:Panel>
</div>
</form>
HOWEVER....(there's always a catch)... with this method, the Validation Messages themselves are stored in the JavaScript only. Meaning that it won't work if Javascript is disabled. I'm assuming that's not a huge problem since you are working in WebForms (which rely on JS), but I figure it's worth mentioning.
And for the record, accessibility concerns are mostly a crock of horse-crap. I THOUGHT I knew about accessibility until I actually worked with a visually impaired programmer (100% blind). Then, I learned that JS works just fine (assuming they know to look for new content...) and that they just skip around the page from link to link until they find what they are after. And table-based layouts didn't slow them down for 1 second. Boy that was a tough pill to swallow after being SOOO unbearably preachy about CSS for a few years....

Updating Database with value from datepicker control ASP.NET VB

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...

Calendar control is not popping-up when clicked on image

I'm using a CalendarExtender control with the help of <img> to populate a TextBox with a date. I am using this in EditItemTemplate of GridView. But when I click on the image, the calendar control is not poping up.
I have used this CalendarExtender control in four or five other places (in this project) also. Everywhere else it is working fine. I have compared the code from the well working version to this code. No difference at all.
I have written the code like below:
<EditItemTemplate>
<asp:TextBox ID="txtDateDelivered" runat="server"
Text='<%# Bind("DateDelivered","{0:dd/MM/yy}") %>'
CssClass="DateTextBoxInGridView" >
</asp:TextBox>
<asp:CalendarExtender ID="calexDateDelivered" runat="server"
Format="dd/MM/yy"
TargetControlID="txtDateDelivered"
PopupButtonID="calDateDelivered">
</asp:CalendarExtender>
<img src="Images/calendar.gif"
id="calDateDelivered"
alt="Calendar" />
</EditItemTemplate>
Can anybody please tell where could be the problem?
how many row do you have in grid? also probably you have more than one image with such id
The image tag which you have used is not a server control.
It is simple html control, this is the reason why the calender control does not reconise this image control..
Try using asp.net image button over here instead of .
It should work then.
cheers....
Rahul C.

ASP.NET 3.5 :No Postback triggered for button click

I have an ASP.NET page developed in VS 2008. there is a text box and login button.Required fireld validator and Validtion Group controls are associate for validation.I wrote code for the Button click evenet handler too.But the Button click is not getting fired.There is no post back happening. Can any one tell me why ?
HTM lmarkup
<asp:TextBox ID="txtLoginPass" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
Validators generate client side JavaScript which can prevent a postback if the required field is empty.
Is that exact code snippet? It didn't work at all - no such control as txtPassword.
Altough, this worked as expected:
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword" ValidationGroup="Login" ErrorMessage="Please enter password." runat="server" />
<asp:Button ID="btnLogin" runat="server" Text="Login"
onclick="btnLogin_Click" ValidationGroup="Login" />
I'm sure that you've got that correct in your code, so the problem must be somewhere else - could please post more code surrounding this snippet?
I expect that you have AutoPostBack="True" on one of your components. If so then remove that and your onclick should work on the button.
I had this same exact problem. The RequiredFieldValidator was working as expected when the textbox was empty, but the button click wasn't causing a postback when there was text. My problem? I was using the same validationgroup name in a separate user control. So make sure all of your validationgroup names are unique.

Resources