views:

38

answers:

3

Actually I have Multiple update panels on page, which update different values on server but the problem is that I have textbox to which I attach javascript class for datepicker on Load event.

But There are other updatepanels before that date TextBox, when I update them first calender image with date control which is in updatepanel disappears. or it remove the calender which is next to the textbox.

txtDate.Attributes.Add("class", "show-week w16em dateformat-d-sl-m-sl-Y"); 

Before using any updatepanel its like this

alt text

After we upfdate any updatepanel control its like this.

alt text

But the Date controls which are not in any updatepanel are ok and working.

And in these updatepanels I actually saving values in DataTables and save these DataTables in viewState .... no change in HTML.

A: 

Are you changing the INNERHTML of the DIV or TABLE in which the TextBox is present because if you are then its removing the calender control after that DIV or TABLE is being updated.

KhanZeeshan
no .... in these panels I actually saving values in DataTables and this I save them in viewState .... no change in HTML.
Azhar
then you have to rebind the calender control after every ajax request like y34h suggested. To Re-Bind the Calender; Sys.Application.add_init(function() { $create(AjaxControlToolkit.CalendarBehavior, {"button":$get("<%=PopupButtonID%>"),"cssClass":"cal_Theme1","format":"MM/dd/yyyy","id":"<%=CalenderEntenderID%>","popupPosition":1}, null, null, $get("<%=TargerControlId%>"));});
KhanZeeshan
A: 

whatever method you are using to attach the datepicker, you must call again after the updatepanel updates

you can do it on server side with this:

// at some point of the method that updates the panel
ScriptManager.RegisterStartupScript(
    this, typeof(object), "someUniqueKey", "theScript();", true);

or on client side with this:

// <body onload='...'> or in the <head>
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
    function () { theScript() });
y34h
+1  A: 

I guess the datepicker and its textbox both are placed in an updatepanel?

If you do an ajax-postback with UpdatePanels the server will send html back for all UpdatePanels on the page, and refresh all of their contents, so your datepicker will disappear.

If you set UpdateMode=Conditional on the UpdatePanels then only the UpdatePanels that caused the postback will update.

Another option is to recreate the datepicker with ScriptManager.RegisterStartupScript, but this possibly resets its value (depends on which datepicker it is).

Willem
ok... but what if that updatepanel also postback or update on server next time same JavaScript problem will be there again
Azhar
True, then you'll have to recreate the datepicker with javascript each time that panel updates, but how to do that exactly depends on the datepicker you use. I guess you run some code onload, try to also load that code on (ajax-)postback.
Willem
ya I did that too but not work ...
Azhar