6/23/2008
As I have am working on my Czech Social networking site, I have come across an interesting challenge: how to create Emoticons in ASP.NET. I come up with the solution, so I would like to share it.
The core is a very simple loop function that replaces sets of characters, with another set:
Public Function Emoticons(ByVal strCharString As String, ByVal strCharSet As String) As String
Dim arrCharSet(30)
Dim arrCharCouple(2)
Dim i As Int32
arrCharSet = Split(strCharSet, ",")
arrCharCouple = Split(arrCharSet(1), " ")
For i = 0 To arrCharSet.Length - 1
arrCharCouple = Split(arrCharSet(i), " ")
strCharString = Replace(strCharString, arrCharCouple(0), + _
"<img src='" + ConfigurationManager.AppSettings("EmoIconsPath") + _arrCharCouple(1) + "' alt='" + arrCharCouple(0) + "' />")
Next
Return strCharString
End Function
Next, put the pair set in the webconfig file:
<add key="EmoIcons" value=":) regular_smile.gif,:-) regular_smile.gif" />
<add key="EmoIconsPath" value="images/emoticons/" />
And lastly, this is how you can call this function from within, let's say the repeater control:
<%#Emoticons(Container.DataItem("comment_body"), ConfigurationManager.AppSettings("EmoIcons"))%>So here is what it looks like in action on the fungu.cz forums' page.
3/23/2008
Some time ago, I have read an interview with Mark Zuckerberg that was focused on how facebook.com develops their code. There was a line that especially caught my interest. Mark mentions that one of the important factors that try to observer when developing new features for facebook is that keep the code flexible enough so that the developers would be able to modify it based on the business needs. This is something that I have also learned in my entrepreneurial endeavors: It makes no sense trying to make your application all perfect and finished before you show it to people. This is especially true if you develop for communities, because you will rarely be able to know all the needs of the community and the design stage, so long and polished development cycles make very little sense.
3/23/2008
I am converted. I must say, I have a very utilitarian approach to computer hardware. I prefer to have the laptop that works well and I don’t have to pay for (because it is given to me at work) Laptops break and age so why to spend money on something that is after all just a tool to get the work done. Well, my recent job change earned me brand new MacBook Pro. Over night, I was forced to switch from Dell Latitude 620, which I thought was the most pragmatic computer until that time, to MacBook Pro. Being the guy that least cared about the “latest greatest,” I must say, I do enjoy the new Mac gadget very much. I use to say, the best thing I like about it is that you can make it an equal windows machine too if you for some reason need to do so. There were a few pains during my conversion period. For some reason the Mac designer decided that they want to switch the order of your control and alt keys, and add another one that sometimes combines the functionality of both. This took really a couple of weeks to get use to, but since it was clear that I most likely will never go back to a PC, I was glad to relearned my shortcuts again.
3/13/2008
I have been spending much time in recent months building ASP.NET websites with jquery as the JavaScript library framework. From these projects I was able to learn much about how to interact jquery with ASP.NET. In this post I will share of the solutions.
If you have been coding AJAX apps for a while, you probably got over doing just simple animations and AJAX requests and now you want to do more than that. I call this the “level two” of AJAX development. The characteristics are when you start using POST as an AJAX method and JSON as your data format for response.
OK, enough theory, let’s get our hands dirty: Let’s take a practical scenario, you are building a social networking site, and you wan to do a simple “add to my friends” functionality to a page that lists your users. Two things need to happened, after you click the “add a friend” button, the user needs to disappear from the “list” (he/she is your friend now, so is being moved to the friends list), second you need to reflect this change in the database.
Hiding friend after the click:
In jquery this is really simple, you can use the .hide() method. The only tricky part is the assign some kind of unique ID that will tell the click event which wrapper div to hide. I one of the easiest ways to do this is you can hide the variable into one of the elements properties: (id, href, or title)
$(document).ready(function(){
$(".add_friend").click(function(){
var strId = $(this).attr("id");
strId = strId.slice(1);
$("#" + arrS[1]).hide();
return false;
});
});And here is the THML part
<div id="id_123">
<!--
Whatever user info you wnat here...
-->
<a href="#id_123" class="add_friend">add to my friends</a>
</div>
Changing of the server: writing the change to the database:
Now we are getting to the POST method. Despite the confusions going around, ding a post in AJAX as simple doing get. It is just one of the properties of the XMLHTTP request. Instead of putting the pairs of values in the query string, you just put it inside of the objects. I have seen developers trying to write HTML of a form inside of IFRAMES… nope that’s not how you do it. Lastly as you are posting to another page, you need to catch you value pars on the page. In ASP.NET is very easy: instead of request.querystring(“id”) which you would be using in your GET method, you just use request.form(“id”)
Here an example what the JavaScript would look like:
$(document).ready(function(){
$(".add_friend").click(function(){
var strId = $(this).attr("id");
strId = strId.slice(1);
$.post("ajax_post.aspx",
{ m: "SharePhoto",
p: arrS[1],
p2: arrS[2],
p3: arrS[1]},
function(data){
});
return false;
});
}); This is how you would be catching the variables on the ASP.NET pag
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
strMethod = Request.Form("m") 'm = method
strProperty = Request.Form("p") 'p = property1
strProperty2 = Request.Form("p2") 'p = property2
strProperty3 = Request.Form("p3") 'p = property3
End Sub
Finally, here are some examples of live sites where I have implemented this:
oznamkujucitele.cz (The voting on this page is actually done through an AJAX POST, although the page refreshes in the end, this refresh is done in JavaScript just refreshes the page to get the next image and the advertising impressions.)
fungu.cz (The digg-like voting.)
3/6/2008
Just wanted to give my readers an update about Dave’s ASP.NET blog and small business CMS. As I mentioned in one of my previous posts, I was approached by a publisher to write a book about creating ASP.NET CMS. This is still in progress, and I hope I am getting in the final stage of the preliminary steps after which I will we will sign a contract with the publisher.
With this being said, I wanted to give some news on where I see Dave’s CMS to be going in the future. On one hand I will keep the blog features, giving an alternative to Word Press for ASP.NET developers (or server owners). On the other hand, I would like to start building some extensions that would make this CMS more appealing to small business. For instance I was thinking about adding an extension for recruiters that would allow recruiters easily insert new job postings, update position descriptions. Apart from the communicational value there is a great SEO value, since the website would be now filled with highly searched keywords contained in position titles.