<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Scott Elkin &#187; Javascript</title> <atom:link href="http://scottelkin.com/category/programming/javascript/feed/" rel="self" type="application/rss+xml" /><link>http://scottelkin.com</link> <description>Tech, Love, Life</description> <lastBuildDate>Thu, 07 Apr 2011 23:02:52 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Emulating Digg Spy using AJAX.NET</title><link>http://scottelkin.com/programming/ajax/emulating-digg-spy-using-ajaxnet/</link> <comments>http://scottelkin.com/programming/ajax/emulating-digg-spy-using-ajaxnet/#comments</comments> <pubDate>Thu, 09 Feb 2006 06:02:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[AJAX]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2006/02/08/Emulating-Digg-Spy-using-AJAX.NET.aspx</guid> <description><![CDATA[In my latest project, I need to build a lead system for our sales people. It will work very similarly to the digg.com/spy application, so I took advantage of their model in order to learn AJAX.NET. I decided to go with AJAX.NET, rather than the new Anthem, just to get my feet wet. I will [...]No related posts.]]></description> <content:encoded><![CDATA[<p>In my latest project, I need to build a lead system for our sales people. It will work very similarly to the <a href="http://digg.com/spy">digg.com/spy </a>application, so I took advantage of their model in order to learn AJAX.NET.</p><p>I decided to go with <a href="http://ajax.schwarz-interactive.de/csharpsample/default.aspx">AJAX.NET</a>, rather than the new <a href="http://anthem-dot-net.sourceforge.net/">Anthem</a>, just to get my feet wet.  I will make it work in Anthem next.</p><p>This is what my example will look like:</p><p><img src="http://www.scottelkin.com/images/beforesubmit.jpg" border="0" alt="Beforesubmit" /><br /> and after you click the button:</p><p><img src="http://www.scottelkin.com/images/aftersubmit.jpg" border="0" alt="Aftersubmit" /><br /> Using AJAX, it went and grabbed a new item, and inserted it to the top row, and removed the bottom row.  Digg’s Spy is obviously nicer, but it does essentially the same thing.</p><p>Yes, there are TONS of ways I can optimize this and make it slimmer and nicer, but his was a proof of concept.  I know I didn’t have to use a DataSet, but since I wanted to see it work, I used it.  I also didn’t care about formatting a date in javascript.</p><p>Here is my code behind code:</p><pre><code>public class test : System.Web.UI.Page
{
   private void Page_Load(object sender, EventArgs e) {
     Ajax.Utility.RegisterTypeForAjax(typeof(test));
   }

   [Ajax.AjaxMethod()]
   public DataSet GetLeads() {
        DataSet ds = new DataSet();
</code><code>        </code><code>DataTable dt = new DataTable("MyTable");
</code><code>        </code><code>ds.Tables.Add(dt);
</code><code>        </code><code>dt.Columns.Add("ID", typeof(int));
</code><code>        </code><code>dt.Columns.Add("Firstname", typeof(string));
</code><code>        </code><code>dt.Columns.Add("Date", typeof(DateTime));

</code><code>        </code><code>dt.Rows.Add(new object[] { 1, "steve", DateTime.Now });
</code><code>        </code><code>return ds;
   }
</code></pre><p>And here is my sample for the .aspx file:</p><pre><code>&lt;html&gt;
&lt;head&gt;
&lt;style&gt;

.lead {
clear: both;
border-top: 1px solid #ccc;
}

#mostrecent { font-weight:bold; }

.column1, .column2, .column3 {
float: left;
display: block;
text-decoration: none;
}

.header span {
font-weight: bold;
background:#eee;
}

.column1 {
width: 6em;
text-align: center;
/*border: 1px solid green;*/
}

.column2 {
display: block;
width: 10em;
/*border: 1px solid blue;*/
}

.column3 {
display: block;
width: 20em;
/*border: 1px solid yellow;*/
}
.button {
clear: left;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt; 

&lt;form id="Form1" method="post" runat="server"&gt;
&lt;div id="leads"&gt;
</code><code>   </code><code>&lt;div class="header"&gt;
</code><code>   </code><code>   </code><code>&lt;span class="column1"&gt;ID&lt;/span&gt;&lt;span class="column2"&gt;Name&lt;/span&gt;&lt;span class="column3"&gt;Date&lt;/span&gt;
</code><code>   </code><code>&lt;/div&gt;

</code><code>   </code><code>&lt;div class="lead" id="mostrecent"&gt;&lt;span class="column1"&gt;54&lt;/span&gt;&lt;span class="column2"&gt;scott&lt;/span&gt;&lt;span class="column3"&gt;1/1/2006&lt;/span&gt;&lt;/div&gt;
</code><code>   </code><code>&lt;div class="lead"&gt;&lt;span class="column1"&gt;22&lt;/span&gt;&lt;span class="column2"&gt;peter&lt;/span&gt;&lt;span class="column3"&gt;1/2/2006&lt;/span&gt;&lt;/div&gt;
</code><code>   </code><code>&lt;div class="lead"&gt;&lt;span class="column1"&gt;12&lt;/span&gt;&lt;span class="column2"&gt;sam&lt;/span&gt;&lt;span class="column3"&gt;1/3/2006&lt;/span&gt;&lt;/div&gt;
</code><code>   </code><code>&lt;div class="lead"&gt;&lt;span class="column1"&gt;44&lt;/span&gt;&lt;span class="column2"&gt;sally&lt;/span&gt;&lt;span class="column3"&gt;1/4/2006&lt;/span&gt;&lt;/div&gt;
</code><code>   </code><code>&lt;div class="lead"&gt;&lt;span class="column1"&gt;51&lt;/span&gt;&lt;span class="column2"&gt;paul&lt;/span&gt;&lt;span class="column3"&gt;1/5/2006&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="button"&gt;
   &lt;input type="button" onclick="buttonClick()" value="blah"/&gt;
&lt;/div&gt;

&lt;script language="javascript"&gt;

function buttonClick() {
   test.GetLeads(GetLeads_CallBack);
}

function GetLeads_CallBack(response){

//SBE 02/08/2006:  create the div element
var newLead = document.createElement('div');

//SBE 02/08/2006:  set its class to lead
newLead.setAttribute('class', 'lead');

var leadTable = document.getElementById('leads');
var rows = leadTable.getElementsByTagName('div');
var numrows = rows.length;
var html = "";

//SBE 02/08/2006:  make sure we got a dataset to loop through
var ds = response.value;
if(ds != null &amp;&amp; typeof(ds) == "object" &amp;&amp; ds.Tables != null){
</code><code>   </code><code>var s = new Array();

</code><code>   </code><code>s[s.length] = "&lt;span class='column1'&gt;" + ds.Tables[0].Rows[0].ID + "&lt;/span&gt;";
</code><code>   </code><code>s[s.length] = "&lt;span class='column2'&gt;" + ds.Tables[0].Rows[0].Firstname + "&lt;/span&gt;";
</code><code>   </code><code>s[s.length] = "&lt;span class='column3'&gt;" + ds.Tables[0].Rows[0].Date + "&lt;/span&gt;";

</code><code>   </code><code>html = s.join("");
}
else{
</code><code>   </code><code>alert("Error. [3001] " + response.request.responseText);
}

//SBE 02/08/2006:  assign the html to the new lead
newLead.innerHTML = html;

oldItem = document.getElementById('mostrecent');
leadTable.insertBefore(newLead, oldItem);
newLead.setAttribute('id', 'mostrecent');
oldItem.setAttribute('id', '');

// remove last row
leadTable.removeChild(rows[rows.length-1]);

}
&lt;/script&gt;
&lt;/form&gt; 

&lt;/body&gt;
&lt;/html&gt;
</code></pre><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/ajax/emulating-digg-spy-using-ajaxnet/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: scottelkin.com @ 2012-02-09 10:14:42 -->
