Perma LinkThe modal popup extender. There are a lot of hooks in this control. The rating control it has a built in callback.
What I learned.
- How to show a modal popup from javascript.
- How to do implement the rating control call back.
Showing a modal popup.
If you've ever looked at my blog page only one entry is loaded and the rest are webserviced in so there can be lots of blog entries. I wanted to have one modal popup that I could use to enter comments on any of the blog entries on my blog page. So I needed a way to show the modal popup from javascript.
Well first you need a modal popup on the page of course. You can look at the ajaxcontrol toolkit sample here. http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ModalPopup/ModalPopup.aspx
All of the extender controls support a property call BehaviorID this comes in very hand. The behaviorid is sent to the client as is without any naming container. Learn about the namingcontainer here and if you haven't noticed msdn is also quieltly adding url rewriters. http://msdn.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx Naming contianer is what creates client ids like CT001_ContentPanel1_Gridview1_BehaviorID_etc
<%--modal poup markup--%>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
BehaviorID="CMX"
...
</cc1:ModalPopupExtender>
//javascript now I can just show it from anywhere.
$find("CMX").show();
The rating control callback. Right out of the javascript for the rating control. It can either to an autopostback or a callback.
if (this._autoPostBack) {
__doPostBack(id, args);
}
else {
WebForm_DoCallback(id, args, this._receiveServerData, this, this._onError, true)
}
Ok I'm going to do the call back the only thing to watch out for is your page_load event on the server. You need to check Page.IsCallBack and skip anything that might cause problems. You know things like reloading your gridview or anything your binding in your page load event.
The call back code for the rating control. I wanted to use this callback for everything and lucky for me there is a tag parm that can be set on the rating control. I set this to the id of my blog post.
$find("Rating").set_Tag(j); //j is my post id
Now back on the server I have tag for the post and can act on it in my call back.
Dim postid As Integer = Integer.Parse(e.Tag)
The return from my call back is just a string.
e.CallbackResult = HttpUtility.HtmlEncode(ret)
Then back on the client I just drop the callback result into a span. There are a few extra steps here because I'm creating a callback handler for a delegate so I can use my own code with the rating control.
this._rating = $find("Rating");
this._ratingdelegate = Function.createDelegate(this, this._callbackRating);
this._ratingHandler = Function.createCallback(this._ratingdelegate, this._somedata);
this._rating.add_EndClientCallback(this._ratingHandler);
...
_callbackRating: function(sender, e) {
var j = this.get_RatingLabelID();
if (j) {
$get(j).innerHTML = e.get_CallbackResult();
}
},
I dispose of the handlers in the popup control hiding event. I just call the remove_ method and then set everything to null.
That's it for now and sorry I've been blank on making posts the last few days.
Good Luck
Comments Perma Link