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)

Tuesday, June 10, 2014

SQL query column with XML stored as VARCHAR

XML stored as VARCHAR can be queried by CASTing

--Example XML

SELECT a.Id, m.Message, a.TransmissionDtTm

FROM Message m

INNER JOIN MessageArchive a ON a.messageid=m.messageid

WHERE a.TransmissionError = 0

AND CAST(m.Properties AS xml).value('(/Props/Type)[1]', 'VARCHAR(128)') LIKE '%Email%'

Thursday, May 22, 2014

Use of Javascript to allow RadioButton grouping to work in Repeater

1.) JavaScript
<script language="javascript" type="text/javascript">
   function RadioSelectionChanged(groupName, current) {
     var group = document.getElementsByName(groupName);

     for (i = 0; i < group.length; i++) {
        //.NET uses a span tag to define the control "name", so the first control in the span control will be the radiobutton        if(group[i].childNodes.length > 0 && group[i].childNodes[0].type == 'radio')
         group[i].childNodes[0].checked = false;
    }     current.checked = true;

2.) Control
<asp:Repeater ID="Rptr" runat="server">
    <asp:RadioButton ID="Rb" runat="server" onclick="RadioSelectionChanged('GroupName', this);" name="GroupName"  />