How does live preview interact with JavaScript and with binding?

Aug 5, 2007 at 12:38 PM
I'm confused as to how Live Preview works. Does it have to do with the BindLivePreview() message in UserControls/CommentView.ascx.cs? Or is it depending on the JavaScript function ShowCommentPreview in blog.js (which is compiled into the dll)?

Right now my LivePreview only updates name and website. (It initially has all of these, but only the name and website and comment text update when you start typing, wiping out the IP and email.) I would like to make it update IP address, email, and avatar, but I'm not sure where to start.

Thanks,
Coordinator
Aug 5, 2007 at 4:06 PM
That would be ideal, but remember that only the IP and e-mail is visible if you are logged in. Other visitors does not see something missing.

To start, you should update both the javascript and the method on the user control you referred to. Thanks
Aug 6, 2007 at 12:51 AM

madskristensen wrote:
That would be ideal, but remember that only the IP and e-mail is visible if you are logged in. Other visitors does not see something missing.

To start, you should update both the javascript and the method on the user control you referred to. Thanks


Wait, so what purpose does BindLivePreview serve at all? It seems like I'm going to have to engage in major code duplication here, especially for the avatar---all the logic for figuring out what avatar it is needs to be replicated in JavaScript now, too?
Coordinator
Aug 6, 2007 at 9:10 AM
Yes, to display the avatar you would need to do in javascript. It can easily be done however, except for the MD5 hashing for the Gravatar, but I have seen it done in javascript. The live preview serves as a mean for people to see how their comment will look like. It also resolve the links.
Aug 7, 2007 at 2:27 AM

madskristensen wrote:
Yes, to display the avatar you would need to do in javascript. It can easily be done however, except for the MD5 hashing for the Gravatar, but I have seen it done in javascript. The live preview serves as a mean for people to see how their comment will look like. It also resolve the links.


I still don't see what the purpose of the server-sided method BindLivePreview is. In my implementation, I think I'm just going to get rid of it entirely... if JavaScript is doing all the work after the page loads, we might as well have it do all the work on the initial page-load as well. That way there's no code duplication either.
Coordinator
Aug 7, 2007 at 8:10 AM
The BindLivePreview loads your themes CommentView.ascx user control so that it looks the same as an actual comment regardless of the theme. It also fills out the name and gravatar if you've already made a comment on your blog before so it has those information in a cookie. If a visitor hasn't made a comment before, that's where you need the JavaScript. So, in other words: you need it :)
Aug 7, 2007 at 9:32 AM

madskristensen wrote:
The BindLivePreview loads your themes CommentView.ascx user control so that it looks the same as an actual comment regardless of the theme. It also fills out the name and gravatar if you've already made a comment on your blog before so it has those information in a cookie. If a visitor hasn't made a comment before, that's where you need the JavaScript. So, in other words: you need it :)


Oh OK, that makes some sense, especially re-reviewing the code and paying attention the parts I wasn't trying to modify. But, I think that all the code for copying values into the comment object should be done in JavaScript instead. Specifically, everything from and including "if (!string.IsNullOrEmpty(txtName.Text))" to (but not including) "control.Comment = comment;" should be omitted and done in JavaScript. Is that sensible? It seems like that code is not doing anything JavaScript could not.