Friday, December 27, 2013

LinkButton OnClick Not Firing After OnClientClick

I worked around an oddball problem where the OnClick event of an ASP LinkButton would not fire following execution of some JavaScript tied to its OnClientClick.

The intent is to enable a row in a Telerik RadGrid to be removed by clicking the corresponding button in the row, and more specifically have a modal confirmation dialog appear to prompt the user to confirm their choice.

Here's markup for the GridTemplateColumn containing the button:
<telerik:GridTemplateColumn HeaderText="Remove" UniqueName="Remove" 
  FilterControlWidth="20">
    <ItemTemplate>
        <div style="cursor: hand;">
            <asp:LinkButton runat="server" ID="_RemoveItem" 
                Name="_RemoveItem" Text=" X " Font-Underline="False" 
                ForeColor="DarkBlue" 
                OnClientClick="confirmAspButton(this, 'Are you sure?'); return false;"
                OnClick="RemoveItemButtonClick" 
                style="font-weight:bold;color:red;">
            </asp:LinkButton>
        </div>
    </ItemTemplate>
    <HeaderStyle Width="55"></HeaderStyle>
</telerik:GridTemplateColumn>

The confirmAspButton function is a little JavaScript which is bound to the OnClientClick method of the LinkButton. If the user clicks OK, the confirmation passes and a postback will occur to execute the code beneath the OnClick method, whereas if they click Cancel the dialog will simply disappear.
     function confirmAspButton(button, message) 
     {
          function aspButtonCallbackFn(arg) 
          {
             if (arg) 
             {
                  window.__doPostBack(button.name, "");
             }
          }
            
          window.radconfirm(message, aspButtonCallbackFn, 330, 120, null, "Confirm");
     }


Seems simple enough, yet for some odd reason, in Internet Explorer 10, the LinkButton brought up the dialog just fine, and although the Cancel button click performed as expected, clicking OK had the same effect as cancel and merely cleared the dialog without executing the underlying code.

I managed to find a workaround via StackOverflow which suggests using a Button rather than a LinkButton. Sure enough, this did the trick, for whatever oddball reason whose particulars I could care less to dive into...




Friday, November 8, 2013

Tuesday, October 1, 2013

Repost!

Occasionally I post links to various content on Reddit. Often, a diligent member of the internet's police force informs me that somehow a given image or link has *gasp* already been posted somewhere else on the internet.


"Repost!"

O NOES! Holy Jar Jar Binks' prolapsed rectum, internet police! 

What many who post this don't seem to realize is that a) their message is pointless, and b) Reddit's popularity is all about the pageviews

Reddit lives for pageviews. Billions of them, and of those millions are by unique visitors. Some of those visitors are smart, some aren't, and a few are dumb as a sack of hammers. That said, if Reddit were something like a think tank (which it isn't) or a Wikipedia-like foundation (nope) instead of a for-profit company, a self-proclaimed “part-sibling-once-removed” of Condé Nast, Inc., it might do things smarter than it does now.



Putting aside respect for the massive popularity of Reddit and the hard work its staff and board and communities provide, Reddit the site isn't that bright when it comes to sniffing out content that's already been posted. 


There is the somewhat anemic search functionality, which conscientious users occasionally invoke to perform keyword searches in search of existing content, and there are third-party sites like KarmaDecay which provide reverse image search capability for specific subreddits or site-wide. However, note that there is no smart search capability exposed to the users which is savvy to detect whether a given link ultimate leads to something that's been posted before.

Granted, they are in the red. Running a site as popular as Reddit is a huge undertaking, and the infrastructure required to support it increases with its popularity. Even if such smart search were a high priority, investing in its development would bleed resources from their daily operations. 

If anything, users of Reddit who cry "repost" should realize that they're doing more to hurt the site than they are to help it. Comments on Reddit can be upvoted and downvoted, which requires processing power and bandwidth. The loading and rendering those comments also takes power. Worse than the fact that telling someone they've reposted something adds nothing of substance to a discussion about the content in question, it's wasting Reddit's resources.

If content is worthy of being reposted, it often generates some constructive discussion, particularly to those for whom it's a novel find that have never, ever, seen it before. Engaging good content rather than whining about that already seen seems far more worthy of Reddit's dedication to community than its users chiding submitters of content one word at a time.



tl;dr: Repost police, get over yourselves and do something useful for a change.