Friday, May 8, 2015

Image on end of TextBox or DropDownBox

Example of how to have image display at start of DropDownList

  background: #ffffff url(/images/icon-search.gif) no-repeat 3px 50%;

<asp:DropDownList ID="NameDdl" runat="server" CssClass="icon"></asp:DropDownList>

Friday, April 10, 2015

Retain scroll position after PostBack

To keep current scroll position after postback, use some jQuery and an ASP HiddenField.

 1.) Add the HiddenField to the page:
<asp:HiddenField runat="server" ID="ScrollPosition" Value="" />

2.) Add the Javascript (requires jQuery)
       <script type="text/javascript">
        $(function () {
            var sp = $("#<%=ScrollPosition.ClientID%>");
            window.onload = function () {
                var position = parseInt(sp.val());
                if (!isNaN(position)) {

            window.onscroll = function () {
                var position = $(window).scrollTop();

Thursday, March 19, 2015

CSS use left, center and right images for border

Create complex borders that requires three images (left, right, center).

Create div with id/class
<div id="border"></div>

#border {
  width: 100%;
  height: 33px
  margin: 0 auto;
  padding: 0;
  text-align: left;
  position: relative;
  margin-top: 0px;
  max-width: 885px;

/* Comma separated list of border images */#border 
background: url(/images/border-l.jpg) top left no-repeat, url(/images/border-r.jpg) top right no-repeat, url(/images/border-c.jpg) top repeat;

Tuesday, October 21, 2014

Catch WebException from HttpWebRequest POST error response.

A WebException will be thrown if a non 200 status code is returned from the server.  To check the message returned, catch it and read the response.

  byte[] buf = Encoding.UTF8.GetBytes(payload);
  httpReq.ContentLength = buf.Length;
  httpReq.GetRequestStream().Write(buf, 0, buf.Length);
  HttpWebResponse resp = (HttpWebResponse)httpReq.GetResponse();

   if (resp.StatusCode != HttpStatusCode.NoContent && resp.StatusCode != HttpStatusCode.NotFound)
    return resp.GetResponseStream(); //Successful response

catch (WebException wex)
  using (var stream = ex.Response.GetResponseStream())

  using (var reader = new StreamReader(stream))

    Console.WriteLine(reader.ReadToEnd()); //Message returned from client

catch (Exception ex)
    // Something more serious happened
    // like for example you don't have network access
    // we cannot talk about a server exception here as
    // the server probably was never reached


Friday, October 17, 2014

Allow HTTP GET and POST of data to an .aspx page.

In Page_Load, use Request directly to allow GET and POST of data from client.

Request.QueryString[] will return value from the GET request of query string. 
i.e., http://[url]?data=somedata
Request.QueryString["data"] //will return "somedata"

Request.Form[] will return value of POST request.

<form action="http://[url]/Default.aspx" method="post">
    <input name="data" type="text" value="somedata" id="data" />
    <input type="submit" name="Button1" value="Button" id="Button1" />
Request.Form["data"] //will return "somedata"

Request[] will look through all the collections below to find a match:

i.e., if Request["data"] is used, the page will accept GET and POST request without specifying which specific method the page will allow.

Wednesday, October 1, 2014

How to fix kubuntu that halts while booting on battery

To fix a machine that freezes during boot when its on battery, follow this:

1.) Edit grub and reboot the machine
     a.) sudo nano /etc/default/grub
     b.) add nolapic between the quotes on the line GRUB_CMDLINE_LINUX=""
     c.) sudo update-grub

The test temporarily, enter into grub during boot up:
1.) Hold left Shift button during boot
2.) Press the 'e' button
3.) Edit the Linux line to include the option acpi=no
4.) Optionally, remove the "quite splash" option from the Linux line to see ubuntu boot up *
5.) Hit Ctrl+x to reboot

*This will also help debug the problem if these instructions don't fix the problem.

Wednesday, July 23, 2014

SQL selecting varchar xml as nodes with namespace to produce multi-row results

Items covered below:

1.) Selecting a VARCHAR column as XML
2.) Selecting XML nodes containing a namespace
3.) Cross Apply XML column to produce multiple rows of results

TABLE example:
    Id INT,
    Data VARCHAR)

Data Column example:

<Props xmlns=""&gt;<Type><Fun>a</Fun><Sup>1</Sup></Type><Type><Fun>b</Fun><Sup>2</Sup></Type></Props>

SQL example:


X.S.value('(NS:Fun)[1]', 'VARCHAR(8)') AS 'Fun',

X.S.value('(NS:Sup)[1]', 'VARCHAR(8)') AS 'Sup'

FROM TestTable


CROSS APPLY [XML].Data.nodes('/NS:Props/NS:Type') AS X(S)