RegisterStartupScript doesn't appear to be working on page postback within update panel
Posted
by Jen
on Stack Overflow
See other posts from Stack Overflow
or by Jen
Published on 2010-06-09T06:57:29Z
Indexed on
2010/06/09
7:02 UTC
Read the original article
Hit count: 280
OK - so am working on a system that uses a custom datepicker control (I know there are other ones out there.. but for consistency would like to understand why my current issue is happening and fix it).
So its a custom user control with a textbox and on Page_PreRender does this:
protected void Page_PreRender(object sender, EventArgs e)
{
string clientScript = @"
$(function(){
$('#" + this.Date1.ClientID + @"').datepicker({dateFormat: 'dd/mm/yy', constrainInput: true});
});";
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, clientScript, true);
//Type t = this.GetType();
//if (!Page.ClientScript.IsStartupScriptRegistered(t, this.ClientID))
//{
// Page.ClientScript.RegisterStartupScript(t, this.ClientID, clientScript, true);
//}
}
Ignore commented out stuff - that was me trying something different - didn't help.
My issue is that this all works fine when I load the page. But if I select something from a dropdownlist causing a page postback - when I click into my date fields they stop working. As in I should be able to click into the textbox and a nice calendar control appears. But after postback there is no nice calendar control appearing!
It's currently all wrapped (in the hosting page) inside an update panel. So I comment out the update panel stuff and the dates are working after page postback. So it appears to be something related to that update panel.
Any suggestions please?
Thanks!!
© Stack Overflow or respective owner