1 Attachment(s)
How crazy am I to use these techniques?
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
Code:
<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>
And some JS above it
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);
});
The BuildRepeater function basically calls the TestRepeaterBindRow function and binds up the data.
Right now test data is
Code:
var clientData = [
{ name: "Rey Bango", id: 1 },
{ name: "Mark Goldberg", id: 2 },
{ name: "Jen Statford", id: 3 }
];
That would come from a web service in real life.
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
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
That TestRepeaterBindRow JS client side function is like 1/3 the size and bulk of the server side vb function...
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???
....
Re: How crazy am I to use these techniques?
What happens when the user disables JavaScript in their browser :)
Gary
Re: How crazy am I to use these techniques?
Quote:
Originally Posted by
gep13
What happens when the user disables JavaScript in their browser :)
Gary
I really don't have that problem since this is an enterprise application for these users - they have to run it to perform their days work. We can require JS not be disabled...
But we can also detect that and give an elegant error message - right?
Re: How crazy am I to use these techniques?
I agree with your approach, asp.net takes care of the backend but can be combersome with the UI. If someone disables javascript then postbacks and other asp script calls don't work anyway. I love that postbacks maintain page state and enable server side events but if we are fixated on this we create an unnessecary limitation.
Re: How crazy am I to use these techniques?
Quote:
Originally Posted by
szlamany
I really don't have that problem since this is an enterprise application for these users - they have to run it to perform their days work. We can require JS not be disabled...
But we can also detect that and give an elegant error message - right?
Sounds good. Not everyone has this ability.
Yes, there are ways to detect when JavaScript is not enabled.
Gary