Saturday, March 24, 2012

CalenderExtender and RequiredField Validator

hi all,

I have a problem with ajax. when I select a date from calendarExtender it shows date, but when I submit the form , right before submitting it clears the textbox.

So to get around of this problem I wrote some javascript on button click that sets textBox value to hidden field then I am getting that value from hidden field.

Now problem is that , even if textbox is not empty, it submits the form ( as required) but display requiredField validator error message also. that I don't want.

I mean after successfully processing the request it showing error message.

Hi

Can you give me code that replicates this behavior?

I think I had this issue once but I'm not sure anymore what triggers it.

With some code I might be able to find it!

Kind regards,
Wim


hi,

here goes my source view,

Remind me on</td><td valign="top">
<asp:TextBox ID="remindon" runat="server" ReadOnly="True" Width="89px"></asp:TextBox>
<asp:Image ID="imgCalendar" runat="server" ImageUrl="~/images1/iconCalender.gif" ToolTip="Click to see and hide the calendar" />
<asp:Button ID="btnAddReminder" runat="server" OnClick="btnAddReminder_Click" Text="Add Reminder" ValidationGroup="reminder" Width="103px" OnClientClick="javascript:setReminder();" />

And here is my java-script,

<script type="text/javascript" language="javascript">

function setReminder()
{
document.getElementById("hiddenRemindMeOn").value=document.getElementById("remindon").value;
if(validateDate(document.getElementById("remindon"))==true)
{
return true;
}
else
{
return false;
}
}
function validateDate(obj)
{
var currentTime = new Date();
var currentMonth = currentTime.getMonth() + 1;
var currentDay = currentTime.getDate();
var currentYear =currentTime.getFullYear();

var s=obj.value;
var arr=new Array();
arr=s.split("/");
var selectedMonth=arr[0];
var selectedDay=arr[1];
var selectedYear=arr[2];
//DateValidation selected date should not be less than current date:
if(s!="")
{
if(selectedYear<currentYear)
{
alert("you can not select a date less than today's date");
obj.value="";
return false;
}
else
{
if((selectedMonth<currentMonth) && selectedYear==currentYear )
{
alert("you can not select a date less than today's date");
obj.value="";
return false;
}
else
{
if(selectedDay<currentDay && selectedMonth==currentMonth)
{
alert("you can not select a date less than today's date");
obj.value="";
return false;
}
else
{
return true;
}
}
}
}
else
{
return false;
}
}
</script>

Now how to hide that required field validator error message , while it's processing form successfully....

waiting for reply..

thanks




oh, I had forgot to post required field validator code here,

here it is

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="remindon"
Display="Dynamic" ErrorMessage="can not be blank" ValidationGroup="reminder"></asp:RequiredFieldValidator>

thanks...


... still waiting for solution.........


Sorry dude I can't work with your code ....

Please provide me with something that I can copy-paste and works!

Kind regards,
Wim


hi,

sorry for incomplete code, here is rest of the calendarExtender code.

rest of code is already given in previous post .

<cc1:calendarextender id="CalendarExtender1" runat="server" cssclass="cal" popupbuttonid="imgCalendar"
targetcontrolid="remindon" EnableViewState="true"> </cc1:calendarextender>

thanks for cooperation


Hi,

No offence but ....

..... still waiting for easy copy-paste code ....

I'm no monkey who takes all your snippets and tries to figure out what goes where, at least take the effort to give me some decent code!

Kind regards,
Wim


Ok I read through this thread again ...

Let's take a few steps back ...

WHAT is your initial goal?

Because by default, the date in the textbox will NOT dissapear!

That's why I asked for YOUR code, and not just some snippets. More like a page that works, AND shows me the wrong behavior.

All the javascript you are adding; writing to hiddenVariable ==> BullShit! This is all obsolete!!!!!!!!!

So please just give me a replication of the code that shows the wrong behavior and lets start from there!

Kind regards,
Wim


I got the problem. my TextBox is read only . when I make it ReagOnly=False , it works fine.

But I have to make it only readonly to force user to select date from calendar only.

Any way Now I am checking for all those at server side. and removed required field validator.

no issue now.......................................................

....thanks u consider my post..........


Hi forums_user,

This thread will answer some questions about why you had that weird behavior:

http://forums.asp.net/t/1188640.aspx

Kind regards,
Wim

No comments:

Post a Comment