Results 1 to 5 of 5

Thread: How crazy am I to use these techniques?

Threaded View

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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???

    ....
    Attached Images Attached Images  
    Last edited by szlamany; Jan 18th, 2011 at 05:22 PM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width