开发者

Calendar Selection

Greetings,

Might be having a brain fart this morning, but I need a way to execute some JavaScript at the conclusion of an operation taking place inside an ASP .NET Ajax Update Panel. How can this be accomplished?

Thanks,

jason

Updated based on responses: I was not entirely clear, as both initial answers were correct given what I was asking. In my case I ONLY want the JS to run when a particular event for the control inside the UpdatePanel 开发者_JAVA技巧is executed, sorry for the confusion.


Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); 

function endRequest(sender, args) {
    // Executed when ajax request finishes, you could check the sender variable 
    // in order to identify which update panel fired the request
}


Here's a good article on it. I think this is exactly what you're looking for:

http://blog.jeromeparadis.com/archive/2007/03/01/1501.aspx

Only caveat is that this sample works against any ajax callback so if you have multiple updatepanels it will fire regardless of which one has completed a roundtrip, etc.


Thanks to KevinP and Darin for their answers. I had actually forgotton about the instance request handlers on script manager. Unfortunetly, in my case I would be firing the end_request everytime the person navigated in the calendar control. I take the blame as I was not clear on all requirements. I have upvoted both of their answers. Here is my final solutions.

(Forgive me this is in VB) Protected Sub mainCalendar_SelectionChanged(ByVal sender As Object, ByVal ev As EventArgs) Dim dtStart As DateTime = mainCalendar.SelectedDates(0) Dim dtEnd As DateTime = mainCalendar.SelectedDates(6)

    Dim alertString As String = _
       String.Format(
          "alert('{0}');", dtStart.ToString("d") + " - " + dtEnd.ToString("d")
       )
    scriptManager.RegisterStartupScript(upCalendar, GetType(String), _
        "alert", alertString, True)
End Sub

In this context the alert is only ever displayed on the selection of a week in the calendar, not when the user changes the month or does something else relating to navigation.

Thanks again to both responders for their help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜