Results 1 to 5 of 5

Thread: How crazy am I to use these techniques?

  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

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How crazy am I to use these techniques?

    What happens when the user disables JavaScript in their browser

    Gary

  3. #3

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

    Re: How crazy am I to use these techniques?

    Quote Originally Posted by gep13 View Post
    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?

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

  4. #4
    Frenzied Member brin351's Avatar
    Join Date
    Mar 2007
    Location
    Land Down Under
    Posts
    1,293

    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.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How crazy am I to use these techniques?

    Quote Originally Posted by szlamany View Post
    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

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