Wednesday, August 29, 2007

keyCode table for Unicode standard

The following is a table defining the keyCode for particular key presses
With this table you can catch key presses using Javascript with the following:
//The javascript functions:
function InKeyRange(e, min, max)
{
  if (min == null)
    min = 0;

  if (max == null)
    max = 65000;

  if (max < min)
  {
    var tmp = min;
    min = max;
    max = tmp;
  }

  var keyCode = (is_nav) ? e.which : e.keyCode;
  return ((min <= keyCode) && (keyCode <= max));
}

// test if the keycode of the key pressed is a numeric key 0-9
function IsNumericKey(e)
{
  return InKeyRange(e, 48, 57);
}

//Call javascript functions from within a textbox
<asp:TextBox Runat="server" onkeypress="return IsNumericKey(event);" Width="35" ID="TB1"></asp:TextBox>

If the key pressed is not within the givin value, the textbox won't accept the input.

Now here is the table defining the keyCodes:









a = 97
b = 98
c = 99
d = 100
e = 101
f = 102
g = 103
h = 104
i = 105
j = 106

k = 107
l = 108
m = 109
n = 110
o = 111
p = 112
q = 113
r = 114
s = 115
t = 116

u = 117
v = 118
w = 119
x = 120
y = 121
z = 122
0 = 48
1 = 49
2 = 50
3 = 51

4 = 52
5 = 53
6 = 54
7 = 55
8 = 56
9 = 57
' = 39
, = 44
- = 45
. = 46

/ = 47
: = 58
= = 61
[ = 91
\ = 92
] = 93
` = 96
return = 13
escape = 27
space bar = 32

Tuesday, August 28, 2007

SQL raising errors as part of transaction

Here is an example of a sql stored procedure with a transaction which can raise an error and return if some condition is met, it will also catch an error from any called procedure and roll-back the transaction if necessary.


BEGIN TRAN

EXEC dbo.some_sql_function @variable

IF(some_condition)
BEGIN
  RAISERROR ('this %s doesn''t exist.', 16, 1, @errordesc)
  RETURN
END

IF (@@ERROR = 0)
BEGIN
  COMMIT TRAN
  SELECT 1
END
ELSE
BEGIN
  ROLLBACK TRAN
  SELECT -1
END

Friday, August 24, 2007

difference between left join and left outer join

There is no difference between a left join and left outer join (or right join and right outer join). The left/right join simply defaults to the left/right outer join. An explaination can be found on MSDN here

Thursday, August 23, 2007

add confirmation pop up to a repeaters link button

If you have a repeater that is creating a LinkButtons that you want the users action to be confirmed by a javascript confimation box, you can follow the following scheme:

1.) Create the repeater in the .aspx file and add the LinkButton:
    <asp:Repeater ID="aRepeater" Runat="server" >
  <ItemTemplate>
      <td>
        <#DataBinder.Eval(Container.DataItem, "title")%>
      </td>
  </ItemTemplate>
  <ItemTemplate >
    <asp:LinkButton Runat="server" ID="Btn" CommandArgument=%#DataBinder.Eval (Container.DataItem, "arg")%>
      Text
    </asp:LinkButton>
  </ItemTemplate>
</asp:Repeater>

2.) Add the javascript confirmation in the head that you want the LinkButtons to use:
<script language="javascript">
  function Confirm()
  {
    return confirm("Are you sure?");
  }
</script>

3.) Override the Repeaters ItemCreated event and add the attribute to the LinkButton:
private void Repeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
  LinkButton btn = e.Item.FindControl("Btn") as LinkButton;
  if (btn != null)
    btn.Attributes["onclick"] = "return Confirm();";
}

4.) Wire-up the delegate in the InitializeComponent section:
this.Repeater.ItemCreated +=new RepeaterItemEventHandler(Repeater_ItemCreated);

That's it.