Showing posts with label select. Show all posts
Showing posts with label select. Show all posts

Wednesday, March 28, 2012

Calling a Script in UpdatePanel

I am having a problem calling javascript from within an update panel.

Here is what I have set up:

When you select a given index on a dropdownlist, the updatepanel is populated with a custom control I built that loads a wysiwyg editor (widgeditor). The editor requires a javascript call to initialize, but the script (which is registered within the UpdatePanel's control collection), does not fire. In fact, no scripts will fire...

I tried using RegisterStartupScript, RegisterLoadScript, and adding a script via a ScriptManagerProxy.

Any thoughts? I feel there must be a way to accomplish this.

Thanks!

Ben

hehe, from the department of answering my own questions:

I found my big lead here - using the ScriptManager.RegisterScriptBlock:

http://forums.asp.net/2/1550428/ShowThread.aspx

...and updated it using the ScriptManager.RegisterStartupScript ... which made everything work lovely.

I figured there was a good answer to this problem.

Ben

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

Wednesday, March 21, 2012

CalendarExtender....

Hello, Everyone

Please can you help me out with this in (VB)...?

I have a form with a calendarExtendar. When I select a date, and a postback happens I lose the selected date value.

Also when I try and insert I get the todays value and not the selected one..

You have any suggestions?

After deleting everything and starting again it works ….very strange


The problem was not solved by deleting everything…. But it help me find out where the problem actually is! The problem lies with the image pop up for the calendar control …. Delete that and you will stop getting the current date after postback… If you know the solution is let me know…


Post some code...though the post back problem sounds more like you have forgotten to put the load methods inside an "If(!Page.IsPostBack)" block.

Ignore


As requested.... Please can you explain further or suggest some reading about "load methods inside an "If(!Page.IsPostBack)"

ProtectedSub SqlDataSource1_Inserting(ByVal senderAsObject,ByVal eAs System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
Dim Textbox22As TextBox = FormView1.FindControl("TextBox22")

Dim Textbox1As TextBox = FormView1.FindControl("TextBox1")

Dim sDateTimeAsString =CStr(Textbox22.Text) +" " +CStr(Textbox1.Text)Dim OpenDateTimeAsDate = DateTime.Parse(sDateTime)

e.Command.Parameters("@.OpenDateTime").Value = OpenDateTime

EndSub

<tr>

<tdnowrap="nowrap"style="width: 235px">

System Target Date of Resolution</td>

<tdstyle="width: 390px">

<asp:TextBoxID="TextBox22"runat="server"Style="position: static"</asp:TextBox>

<asp:Imagerunat="Server"ID="Image2"ImageUrl="~/images/Calendar_scheduleHS.png"/>

<asp:RequiredFieldValidatorID="RequiredFieldValidator8"runat="server"ControlToValidate="TextBox22"

ErrorMessage="Select Target date"Style="position: static"InitialValue="Select Date">*</asp:RequiredFieldValidator>

<cc1:CalendarExtenderID="CalendarExtender2"runat="server"

TargetControlID="textbox22"

PopupButtonID="Image2"Format="dd MMM yyyy"CssClass="Calendar">

</cc1:CalendarExtender>

</td>

</tr>

<tr>

<tdnowrap="nowrap"style="width: 235px; height: 21px">

System Target Time of Resolution</td>

<tdstyle="width: 390px; height: 21px">

<asp:TextBoxID="TextBox1"runat="server"Style="position: static" </asp:TextBox>

<asp:RequiredFieldValidatorID="RequiredFieldValidator9"runat="server"ControlToValidate="TextBox1"

ErrorMessage="Select Target Date"Style="position: static"InitialValue="Enter Time HH:MM">*</asp:RequiredFieldValidator></td>

<cc1:MaskedEditExtenderID="MaskedEditExtender3"

runat="server"

TargetcontrolID="TextBox1"

Mask="99:99"

Masktype=Time

MessageValidatortip=True

AcceptAMPM=False

/>

</tr>

CalendarExtender with ImageButton problem........

In this application,when you press the ImageButton ,the calenda will show; when you press the ImageButton again or select a date ,the calenda will disappear..

But what I wanna realize is that ,when you click the rest of the page ,the calenda will also disappear, how to realize that??

Thank you very much!!!!!!!!!

Default.aspx

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="http://links.10026.com/?link=StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br /><br />
<b>Calendar with associated button:</b><br />
<asp:TextBox ID="Date3" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Calendar_scheduleHS.png" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="Date3" PopupButtonID="Image1">
</ajaxToolkit:CalendarExtender>

</form>
</body>
</html>

Hi liuyan,

This is an issue of the Ajax Control Toolkit that is known for a while now.

It is even something that will be fixed in an upcoming release of the Toolkit.

You should check the website. This is a direct link to the Issue you talk about.http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=7571

Look at the comments on that site: They include a workaround for this issue until it is fixed in the upcoming release.

Hope this helps!
Kind regards,
Wim


Hi liuyan,

For you situation, I think the easiest way is when hide the Calendar manually when OnClientDateSelectionChanged event occurs. Here is the sample you can refer to:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"
Format="yyyy-MM-dd" PopupButtonID="Button1"OnClientDateSelectionChanged="function hideCalendar(calendar) { calendar.hide(); }">
</ajaxToolkit:CalendarExtender>
<asp:Button ID="Button1" runat="server" Text="Calendar" />

I hope this help

Best regards,

Jonathan