Ok - so this thread http://www.vbforums.com/showthread.php?t=636687
got me thinking about what was good and bad about the whole postback model and updatepanels and such and whether jquery and jtemplates or whatever was a better practice...
At first I thought I needed to retain the PAGE_LOAD event and have ASP.NET build the initial page - but have since considered that to be an unnessecary step...
So this is what we've created and are considering using instead:
Homegrown repeater
And some JS above itCode:<div id="TestRepeater"> <div id="TestRepeater-itemTemplate" style="visibility:hidden"> <div id="divTest">Divs are now labels.</div> <input id="buttonTest" type="button" onclick="alert('test')"/> <input id="textTest" type="text" /> <input id="checkTest" type="checkbox" /> <input id="radTest" type="radio" /> </div> </div>
The BuildRepeater function basically calls the TestRepeaterBindRow function and binds up the data.Code:function TestRepeaterItemCommand(RowDivId, CommandName, CommandArgument){ //called when button or other commandfiring input clicked. alert(CommandArgument); var RowDiv = document.getElementById(RowDivId); var divTester = GetRptrElement(RowDiv, "divTest"); divTester.innerHTML = CommandName; alert(CommandArgument); } function TestRepeaterBindRow(RowDiv, RowData){ var divTester = GetRptrElement(RowDiv, "divTest"); var buttonTest = GetRptrElement(RowDiv, "buttonTest"); divTester.innerHTML = RowData.name; SetCommandClick(RowDiv, buttonTest, "DoUpdate", RowData.id); } $(document).ready(function() { BuildRepeater("TestRepeater", clientData); });
Right now test data is
That would come from a web service in real life.Code:var clientData = [ { name: "Rey Bango", id: 1 }, { name: "Mark Goldberg", id: 2 }, { name: "Jen Statford", id: 3 } ];
At any rate - I compare these events and the code above to what I've done with ASP.Net repeaters and such and it's basically the same logic - actually in some ways the "binding" to elements is much less wordy.
Compare to a typical vb-code-behind bound event
That TestRepeaterBindRow JS client side function is like 1/3 the size and bulk of the server side vb function...Code:Protected Sub RepeaterDummy_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles LogRptr.ItemDataBound Dim uLbl As System.Web.UI.WebControls.Label Dim uTypeLbl As System.Web.UI.WebControls.Label Dim DescLbl As System.Web.UI.WebControls.Label Dim StepsLbl As System.Web.UI.WebControls.Label Dim Status1Lbl As System.Web.UI.WebControls.Label Dim Status2Lbl As System.Web.UI.WebControls.Label Dim ResLbl As System.Web.UI.WebControls.Label Dim DateLbl As System.Web.UI.WebControls.Label Dim LogLbl As System.Web.UI.WebControls.Label Dim UserLbl As System.Web.UI.WebControls.Label Dim rec As DataRowView = e.Item.DataItem uLbl = DirectCast(e.Item.FindControl("UserLbl"), System.Web.UI.WebControls.Label) uTypeLbl = DirectCast(e.Item.FindControl("UserTypeLbl"), System.Web.UI.WebControls.Label) DescLbl = DirectCast(e.Item.FindControl("DescLbl"), System.Web.UI.WebControls.Label) StepsLbl = DirectCast(e.Item.FindControl("StepsLbl"), System.Web.UI.WebControls.Label) Status1Lbl = DirectCast(e.Item.FindControl("Status1"), System.Web.UI.WebControls.Label) Status2Lbl = DirectCast(e.Item.FindControl("Status2"), System.Web.UI.WebControls.Label) ResLbl = DirectCast(e.Item.FindControl("ResolutionLbl"), System.Web.UI.WebControls.Label) DateLbl = DirectCast(e.Item.FindControl("DateLbl"), System.Web.UI.WebControls.Label) LogLbl = DirectCast(e.Item.FindControl("LogId"), System.Web.UI.WebControls.Label) UserLbl = DirectCast(e.Item.FindControl("UserId"), System.Web.UI.WebControls.Label) uLbl.Text = rec(0).ToString uTypeLbl.Text = rec(1).ToString DescLbl.Text = rec(2).ToString StepsLbl.Text = rec(3).ToString Status1Lbl.Text = rec(4).ToString Status2Lbl.Text = rec(5).ToString ResLbl.Text = rec(6).ToString DateLbl.Text = rec(7).ToString LogLbl.Text = rec(8).ToString UserLbl.Text = rec(9).ToString End Sub
Why use code behind to build your presentation layer????
Look at the page itself - it's sitting in a nice tab control that we are using from a jquerytools download...
Why have I been drinking all this asp.net postback koolaide???
....




Reply With Quote