Wednesday, December 19, 2012

cms מומלץ

mvc - by gnadysh

Wednesday, December 12, 2012

SQL Group By And Group_Concat Exapmle

SUBSTRING((SELECT ', ' + CAST([קוד זיהוי] AS VARCHAR(20))  FROM [dbo].[All] AllSub
     WHERE AllSub.משפחה = AllMain.משפחה
     For XML Path('')), 2, 8000) AS [קוד זיהוי]
FROM [dbo].[All] AllMain
GROUP BY משפחה, [שם] ,[רחוב] ,[מספר בית], [עיר];

point is that whatever field that is not in the GROUP BY the SQL Server wants you to group it somehow, and you need to to this XML trick for each one.

Tuesday, November 6, 2012

Do Stuff Every Request

say i want to update the login table everytime the user makes any request

scenario 1: no webmethods or ajax:

from the great collection of events in Global Asax we have 3 that fires with each request And knows the Session:
void Session_Start(object sender, EventArgs e){}
void Application_AcquireRequestState(object sender, EventArgs e){}
*here is ur code like pageload ect. btw
void Application_PostRequestHandlerExecute(object sender, EventArgs e){}

so in any of those i can put an sql query and use Session.SessionID or Session["myvar"]
NOTE! that since only PostRequest is executed after ur page finished his code that any changes made to the Session will only appear to him. Also in the very 1st run it will always be empty.

scenario 2: webmethods or ajax:

well i only tested that with page webmethods and PageMehtods, $.ajax and $.post client side.
i found out a few nice thing, fisrt of all from these 3 event only
Application_AcquireRequestState is fired.

on a side note i also found out how to recognize requests - with
Request.Headers, currently i'll just put the expample of skipping if its a JQ:
//jquery:            Accept: application/javascript, */*;q=0.8
//ajax to webmethod: Accept: application/json, text/javascript, */*; q=0.01
if (Request.Headers["Accept"] != null
    && Request.Headers["Accept"].Contains("javascript")
    && !Request.Headers["Accept"].Contains("json"))
thx fiddler! 

Wednesday, October 31, 2012

Run JS from C#, RegisterStartupScript example

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp",
    "<script type='text/javascript'>ArrangeDGV();makeEfferctForGrid();</script>",

just put it somewhere in the page class and it will run the relevant JS funcs, very usefull with UPP

Wednesday, October 17, 2012

MySql Left Join Where Column Is Not Value

well, usually ppl do stuff like
LEFT JOIN B ON = B.id_of_A

but i had a better situation
i had multiple left joins and one of the tables had all kind of values where i needed on of them so its like

SELECT A.*, C.c1, D.c1
IF (B.value = 'myVal', 1, 0) AS bval
LEFT JOIN B ON = B.id_of_A
LEFT JOIN C ON = C.id_of_A
LEFT JOIN D ON = D.id_of_C

so if u out some extra left joins there OR A->B is 1->n our if is not so good like
Table B:
id_of_A | value
1  | 1
1  | 2
1  | 3
1  | 4
1  | 5
2  | 4
2  | 5

and what if i want to WHERE this IF (WHERE bval = 1)?
maybe some1 thinks right join but that will cut the rest of my info

so i need a left join that is a right join ha ha!!

well we can make it work like this:

SELECT A.*, C.c1, D.c1, B.value
LEFT JOIN B ON = B.id_of_A
                        AND B.value = 'myVal'
LEFT JOIN C ON = C.id_of_A
LEFT JOIN D ON = D.id_of_C


what's the difference u ask?
without the [AND B.value = 'myVal'] B.value could be [1-5] and i want where its not [2] so null would return even if is has [3], but now B.value is selected only if the value is [2] so if there is a row with value [3] it will come as a null

want more?
LEFT JOIN B ON = B.id_of_A
     AND B.value = '1' AS BofOne
LEFT JOIN B ON = B.id_of_A
     AND B.value = '2' BofTwo

Tuesday, October 16, 2012

Advanced HtmlTable / GridView auto sort example

this is an expansion for this

this time i just decided to bring all the code and comment it

//* @author James Padolsey (

jQuery.fn.sortElements = (function () {
    var sort = [].sort;
    return function (comparator, getSortable) {
       getSortable = getSortable || function () { return this; };
       var placements = () {
            var sortElement =,
                  parentNode = sortElement.parentNode,
                  nextSibling = parentNode.insertBefore(
return function () {
                if (parentNode === this) {
                    throw new Error("You can't sort elements if any one is a descendant of another.");
                parentNode.insertBefore(this, nextSibling);

       return, comparator).each(function (i) {

//from now on my code

//here i sort the elements by their innerText or date if needed
function MakeTableSortable(tableID) {
     $("#" + tableID + " th").click(function () {
         var index = this.cellIndex;
         if ( == null) { = true; }
         else { = !; }

         $("#" + tableID + " tr").sortElements(function (a, b) {
                if (a.cells[0].tagName == "TH" || b.cells[0].tagName == "TH") {
                return 0;

            var _a = a.cells[index].innerText.toLowerCase();
            var _b = b.cells[index].innerText.toLowerCase();

            //test if _a&_b r datetime
            var _da = MakeMyDate(_a);
            if ('Invalid Date' != _da) {
                _a = _da;
                _b = MakeMyDate(_b);

            //test if number
            if (/^\d+$/.test(_a)) {
                _a = parseInt(_a, 10);
                _b = parseInt(_b, 10);
            if (!a.parentNode.rows[0].cells[index].abc) {
                if (_a > _b) return -1;
                if (_a < _b) return 1;
                return 0;
            if (_a > _b) return 1;
            if (_a < _b) return -1;
            return 0;

     //this is just from the hand on the TH
     $("#" + tableID + " th").each(function () {
         $(this).hover(function () { $(this).css("cursor", "pointer"); },
            function () { $(this).css("cursor", "auto"); });

//this is so that the only thing i need to do is add the js reference
window.onload =
function () {
    var tables = document.getElementsByTagName("table");
    for (var i = 0; i < tables.length; i++) {

//but there was a case. p.s. if the table won't sort 2 ways but only 1 it can be cuz the onload works plus u put this so every click sorts it twice
function ManualySetAllTablesSortable() {
    var tables = document.getElementsByTagName("table");
    for (var i = 0; i < tables.length; i++) {

//and finally the Date object wouldn't parse right my datetime format, also for some mysterious reason it parsed a month earlier like 09 to Aug, so i had to adjust that, my advice is to test it and/or re-write it as needed
function MakeMyDate(strdate) {
    var yy = strdate.substring(6, 10);
    var MM = strdate.substring(3, 5);
    MM = parseInt(MM, 0) - 1;
    var dd = strdate.substring(0, 2);
    var hh = strdate.substring(11, 13);
    var mm = strdate.substring(14, 16);
    var ss = strdate.substring(17, 19);
    return new Date(yy, MM, dd, hh, mm, ss, 0);


Wednesday, October 10, 2012

JQuery set a selected by text or value

this little thing was anoying enouth to find
$("#myDropDownList option:selected").text($("#Whatever").val());
$("#myDropDownList option:selected").val($("#Whatever").val());

JQuery Modal Dialog how to add '-' (minimize)

this is a nice trick
1st to put the '-' in out modal title bar (this is after opening the dialog):

var header = document.getElementById("divMyDialog").previousSibling;
var minusDiv = document.createElement("div");
minusDiv.innerHTML = "&nbsp; - &nbsp;";
minusDiv.setAttribute("class", "divMinusForDialog")
minusDiv.setAttribute("onclick", "MinimizeDialog()")

also put these JS functions:
function MinimizeDialog() {

function MaximizeConvDialog() {
the CSS is this with extra for out maximizer:
.divMinusForDialog {
position: absolute;
   right: 0px;
   font-size: large;

#divConvIsMinimized{   display:none;

and now just put something as maximizer:
<div id="divDialogIsMinimized" onclick="MaximizeDialogDialog()">
    <img src="Images/minimizedCall.jpg" width="100px" />


JQuey Modal Dialog Cancel the X

the title part is the a previous sibling element to your div element and indside it there is the 'X'

   autoOpen: true,
   open: function (event, ui) {
       var header = document.getElementById("MyDialog").previousSibling;