How does live preview interact with JavaScript and with binding?

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.

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?

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.

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.

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 :)

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.