Mental Jetsam

By Peter Finch

Google Developer Day 2011 HTML 5 Challenge

Posted by pcfinch on August 22, 2011

I entered the Google Developer Day 2011 HTML5 challenge, to create a “Google doogle” of the Developer Day Logo entirely in HTML, and I actually made the cut… top 3 in Australia, I’m very happy :-)

https://sites.google.com/site/opencallforgdd/the-challenge-1

http://www.peterfinch.me/gdd2011/

Posted in HTML, javascript, Personal | Leave a Comment »

Accessing DataSource values from within a DataList ItemTemplate

Posted by pcfinch on June 29, 2011

The following C# (ASP.NET) code example shows a couple of ways to access the values returned by a asp:SqlDataSource from within a asp:DataList asp:ItemTemplate. The difficult part was accessing the data sources values and passing them to nested ASP controls like asp:Buttons and asp:ImageButtons.

<asp:SqlDataSource ID="ds" runat="server"
  ConnectionString="<%$ ConnectionStrings:portal %>"
  SelectCommand="select did, title, did from documents">
</asp:SqlDataSource>
<asp:DataList ID="dl" runat="server" DataSourceID="ds">
  <ItemTemplate>
    <div class="result">
      <a href='details.aspx?id=<%#Eval("did")%>>
      <div class="title"><%#Eval("title")%></div>
      <asp:ImageButton ID="butDelete" runat="server"
        ToolTip="Delete"
        ImageUrl="images/delete.png"
        OnClick="butDelete_Click"
        OnClientClick="javascript:confirm('Block comment thread?')"
        CommandName="delete"
        CommandArgument='<%# DataBinder.Eval(Container, "DataItem.did") %>' />
    </div>
  </ItemTemplate>
</asp:DataList>

In order to response to a click on one of the dynamically generated delete buttons use the following code.

protected void butDelete_Click (object sender, ImageClickEventArgs e)
{
  String command = ((ImageButton)sender).CommandName;
  if ("delete" == command) {
    int dId = Int16.Parse(((ImageButton)sender).CommandArgument);
    using(portalConnection portal = new PortalConnection())
    {
      portal.Delete(dId);
    }
    dl.DataBind();
  }
}

Posted in C#.NET | Leave a Comment »

Pop-up message in JQuery Mobile

Posted by pcfinch on May 10, 2011

The following code can be used to pop-up a message in JQuery Mobile similar to an Android “toast”.

$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>Sorry, what was incorrect. Please try again.</h1></div>").css({ "display": "block", "opacity": 0.96, "top": $(window).scrollTop() + 100 })
  .appendTo( $.mobile.pageContainer )
  .delay( 1500 )
  .fadeOut( 400, function(){
    $(this).remove();
  });

BTW… I Love JQuery Mobile!!!!

Posted in JQuery | 6 Comments »

ASP.NET catch “A potentially dangerous Request”

Posted by pcfinch on April 7, 2011

ASP.NET has a handy little feature enabled that filters requests that may be dangerous from the application. One of these is a check for HTML code that may be in a response field in order to avoid the possibility of injecting malicious code onto websites. It’s a nice security feature, and easy to disable by just adding “ValidateRequest=’false’” to the Page directive.


<%@ Page Language="C#" MasterPageFile="~/site.master" AutoEventWireup="true" CodeFile="myWebPage.aspx.cs" Inherits="details" Title="Test" ValidateRequest="false"%>

However, if you want to leave it turn on but avoid the nasty C# exception, that gets thrown when it happens, you can either override the default error page in ASP.NET or the following code can catch (trap) the HttpRequestValidationException exception and render a custom message, or redirect to your own error page.

public partial class myWebPage: System.Web.UI.Page {
 virtual public void ProcessRequest(HttpContext context) {
   try {
     Page.ProcessRequest(context);
   } catch (HttpRequestValidationException) {
     context.Response.Write("Danger");
   }
 }
}

I’m not sure if this is the official way to do it, but it works.

 

Posted in C#.NET | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.