1

I have a homemade toolbar control that is used in several places, both in an UpdatePanel and outside of one. It relies on some jQuery to set up its buttons. It has its own startup script embedded in its assembly.

What I'm having trouble with is getting the startup script to run at the right time when the toolbar is in the update panel. Since it's declared in a hidden panel in the update panel's markup, it gets created and loaded when the update panel is created. But it doesn't actually get rendered until the user has done a couple of things and the hidden panel is made visible.

What I would like is for the startup script to run every time the update panel refreshes. (Ideally I'd like it to only do that if the toolbar is visible, but I'll take "every refresh" if I have to.) But I want the toolbar to still function when outside an update panel, when all it needs to do is hook into the document's .ready() handler.

Given that the toolbar can't tell (as far as I know) from the server side whether it's inside an update panel or not, but is responsible for ensuring the necessary javascript, how can I make this happen?

Thanks.

ETA: I found an answer in the answer to this question. This works for my toolbar whether it's in the update panel or outside of one. Thanks, everybody!

Community
  • 1
  • 1
Ann L.
  • 13,760
  • 5
  • 35
  • 66
  • Not sure if this helps but I think you can tell on the server side whether your updatepanel has caused a postback using the ScriptManager.GetCurrent ( Page ).IsInAsyncPostBack method. Would that work in your case? – Jason Turan Oct 30 '11 at 19:49
  • @JasonTuran Hmm. Maybe, but from the sound of it it would just tell me that an update panel had posted back, not whether the panel that had posted back was an ancestor of my control. For that I suppose I would have to climb the hierarchy of .Parent properties. But thank you! – Ann L. Oct 30 '11 at 20:44

1 Answers1

0

Correct me if I'm wrong but I would think that the jQuery toolbar within the UpdatePanel should be executed everytime that the updatepanel is updated. So maybe on the server side you can tell whether it's a asyncpostback. If it is then you can use write some javascript within the update panel that will be executed. You might use a literalcontrol that you load into a placeholder within the update panel. Something like...

public void WebForm1_OnLoad(Object sender, EventArgs args){


    if(ScriptManager.GetCurrent(Page).IsInAsyncPostBack){
        var con = new LiteralControl("INSERT javascript here that would call jquery method");
        this.placeHolder.Controls.Add(con);
    }
}
Jason Turan
  • 1,302
  • 12
  • 20
  • I found an answer posted to another question that solved my problem. But thank you for your replies! I'm giving you credit for answering the question. Thank you! – Ann L. Oct 30 '11 at 23:46
  • 1
    Ann: It would be helpful for others if you posted the link to the findings. –  May 15 '13 at 08:03