Jquery.selectbox inside updatepanel fails postback

For an ASP.NET website I worked on a while ago I’ve use the jquery selectbox to make the dropdownlist look a little nicer (this is just an ugly example, I’m not a designer):

JQuery selectbox

This looks great and worked great until the dropdownlist was placed inside an updatepanel. The first time the paged was loaded it looked just like it should, but after the first postback the dropdownlist turned back to the default style:

JQuery selectbox

I found rather quickly what the problem was, but it took me some time before I found the solution. That solution is very simle, just put add this code to the Page_Load event

if (this.IsPostBack)
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'>$('select').selectbox();</script>", false);

Hope it helps you…

Comments are closed.