AjaxControlToolkit & RequiredFieldValidator compatibility issue - asp.net

I had a ASP.NET webpage with several text boxes (WebControls) with mandatory data entry. Hence, the text boxes have an associated RequiredFieldValidator & this form was working fine.
Recently, I had to add an additional textbox which accepts date as input. To enforce correct date format, I decided to associate this textbox to the CalendarExtender of the AjaxControlToolkit, so that on clicking the textbox a pop up calendar appears. After successful build of the project, when I navigate to the page an error message “Assembly AjaxControlToolkit does not contain a web resource with name jquery” is returned.
It was also observed that when I deleted all the text boxes & their associated RequiredFieldValidators the Form is working fine. That is when the textbox with CalendarExtender is clicked the Calendar appears without any problem.
It appears that AjaxControlToolkit (ToolkitScriptManager) & RequiredFieldValidator cannot co-exist on a web form. I am using Visual Studio Professional 2012.
Any suggestions ?. Thanks in advance.

Please follow the following steps:
Register Assembly, Namespace and TagPrefix
Than put ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
Try the following code for calendar popup:
<asp:TextBox ID="myTextBox" runat="server" CssClass="textBoxStyle" Width="282px">
</asp:TextBox>
<asp:ImageButton ID="myImg" runat="server" ImageUrl="~/myImage.png"/>
<cc1:CalendarExtender ID="calendarId" runat="server" PopupButtonID="myImg"
TargetControlID="myTextBox" Enabled="True">
</cc1:CalendarExtender>

Related

asp:RequiredFieldValidator makes postback with empty fields

I've faced the following problem with my aps validator. I have a textbox with asp validator. When the user leaves the textbox empty and click on the submit button the validation message shows, but the page does a postback. Any ideas what may cause this happen?
Heres the validator:
<asp:RequiredFieldValidator ID="valReqName" runat="server"
ControlToValidate="txtName" Display="Dynamic" ErrorMessage="blq blq">
</asp:RequiredFieldValidator>
<asp:TextBox ID="txtName" style="font-family:Tahoma, Geneva, sans-serif;
color: #4F4F4F;" runat="server">
</asp:TextBox>
Many thanks,
Anton
EDIT
I have two tabs in an UpdatePanel. The validation problem is part of the second tab, where the user makes some inputs. When I've remove this trigger:
<asp:AsyncPostBackTrigger ControlID="lnkUpload" EventName="Click" />
The postback problem was solved, but another problem occurred. Well at least the postback is removed. Thanks for all answers.
(lnkUpload is the id of the second tab linkbutton)
EDIT 2
Well here is the solution. It appears that my problem was the same like in this article. http://jeffreypaarhuis.com/2011/08/08/validation-not-working-in-updatepanel/
I'm posting the solution as it might be useful for someone else.
"This is the problem:
When a validator is loaded on the page it creates a bit of javascript to support the clientside validation. When you place a validator inside an usercontrol that isn´t visible by default, and this usercontrol is in an updatepanel, it does not create that javascript properly.
This is the solution:
Outside the updatepanel, I did above, create a dummy validator with a dummy textbox using a dummy validationgroup like so:"
<%--dummy validator to make ajax validation possible--%>
<asp:RequiredFieldValidator runat="server" CssClass="hidden" ControlToValidate="dummyTextBox" ValidationGroup="dummy"></asp:RequiredFieldValidator>
<asp:TextBox runat="server" ID="dummyTextBox" CssClass="hidden"></asp:TextBox>
It appears that my problem was the same like in this article.
Have you tried the solution in this thread:
ASP.net RequiredFieldValidator not preventing postback
Remove the following line from web.config
<xhtmlConformance mode="Legacy"/>
"If I remove the line, my validation works the way I expected it to. Googling that uncovered a bunch of blog posts about how VisualStudio adds that line to the web.config when upgrading web apps from .net 1.1 to .net 3.5.
The blog posts were mainly complaining about how that field interferes with .net's AJAX stuff, but I'm guessing it messes with the JavaScript emitted for the RequiredFieldValidator in a similar fashion."
Please add ValidationGroup to your validator(valReqName) and button.
Add this attribute to your validator.
EnableClientScript="True"

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.

An extender can't be in a different UpdatePanel than the control it extends asp.net

I am getting this error "An extender can't be in a different UpdatePanel than the control it extends". what could be the reason and how to tackle this problem.
You are using an AJAX ToolKit Extender Control to extend the functionality of one of your ASP.NET Controls. You have placed the Extender Control in a different UpdatePanel than the one the Extended Control resides in.
Both Extender and Extended controls must reside in the same UpdatePanel to avoid this exception.
Both Extender and Extended controls must reside in the same UpdatePanel to avoid the exception, this solved my problem.
I had an extra UpdatePanel that was giving this error, so I just had to remove the extra update panel lines of my aspx web page code.
What it says really - you've got an extender control that relates to a control that is in a different updatepanel. This means the extender is unable to act properly on the control it extends. You'll need to move your extender to be within the same updatepanel as the main control
In my case I was using button...outside the Update panel as below shown....
<asp:Button ID="btnClub" runat="server" Text="Club" OnClick="btnClub_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
I just solved it by putting the <asp:Button ID="btnClub" runat="server" Text="Club" OnClick="btnClub_Click" /> inside the
update Panel
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnClub" runat="server" Text="Club" OnClick="btnClub_Click" />
Here you make your panel code
</ContentTemplate>
</asp:UpdatePanel>
Reason :Your iD is mis matching Ex:Text box id or dropdown id mismatch in Calender extender or RequiredFieldValidator
Ex:
Hear Id Value And Target Control Id Must Match .....
Check for controls with extenders that are have the same ID especially if you copy pasted from another form
Hi I got the solution of my problem by myself. The problem occurred when the target
control id of the extender control was different from the control it
had extend inside update panel. I resolved this proble a long time
back and replying now.

AjaxControlToolkit CalendarExtender Control not working in my website

I' using the AjaxControlToolkit CalendarExtender in my web site but after uploading it does how show the calendar control. I have registered the control on the page itself. The page postback when I click the image on which I applied the control.
What can be the reason of this?
Check whether you added ToolkitscriptManager in your page, which is in AjaxToolkit
If you are using an ImageButton to show the calendar,
then use ajax control toolkit and put these controls
<asp:ToolkitScriptManager runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="calIcon.jpg" />
<asp:CalendarExtender ID="CalendarExtender1" TargetControlID="TextBox1"
PopupButtonID="ImageButton1" runat="server">
</asp:CalendarExtender>
If you are still getting the page postback when clicking the ImageButton, you can add onClientClick='return false;' to the imageButton
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="calIcon.jpg"
OnClientClick="return false;" />
Drag and place Script manager at top of the ajax control or at top of the form.
As you said that ajax calender works fine on local but when you uploaded it it started creating problems following are the workarounds give them a try.
Check that whether you uploaded the ajax toolkit dll on the server or not.
secondly make sure that you uploaded updated web.config file.
let me know if its helpful otherwise i will try finding other workarounds

ASP.net scriptmanager and AJAX control

im making a username availability check in ASP.net using ajax updatepanel, but i keep getting the following error
The control with ID 'UserNameUP' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.]
im using the create user wizard, to create a new user but i want to check if the user already exists, i have the following code in the aspx file
<asp:UpdatePanel runat="server" ID="UserNameUP">
<ContentTemplate>
<asp:TextBox ID="UserName" runat="server" Width="200px" AutoPostBack="true" OnTextChanged="Username_Changed"></asp:TextBox></ContentTemplate> </asp:UpdatePanel><br />
but i keep getting that error, can any one help
thanks
Before your update panel, make sure you have a scriptmanager:
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
Do you have a script manager inside a master page? That can cause the "Only one instance of a ScriptManager can be added to the page" error?
Or, if its DNN, there is one on each "page" by default.

Resources