Posts

Showing posts from August, 2012

Simple Javascript Regex

some overview about what JS offer in terms of regex http://www.javascriptkit.com/javatutors/redev3.shtml more info about the use of RegExp object \ http://www.w3schools.com/jsref/jsref_obj_regexp.asp and a simple example i found somewhere for PW check: $( function () {    $( '#txtNewPW' ).keyup( function () {       $( 'div.errorRegexPw' ).hide();       var inputVal = $( this ).val();       var numericReg = /<% = PWRegex %>/;       if (!numericReg.test(inputVal)) {           $( this ).after( '<div class="errorRegexPw">Not A Valid Password.</div>' );       }    }); }); thing is that to init the RegExp obj u just need to do var regex = /pattern/; with the 2 '/'. now all u need to do is regex.test(string_to_test) and get true or false like: var regex = /ariel/; var t = regex.test( "ariel" ); var f = regex.test( "arik" ); here t will be t

Pass Complex Data / Class / Form to WebMethod with PageMethods / Ajax

http://encosia.com/using-complex-types-to-make-calling-services-less-complex/ this is how to use JS / JQuery to make an object to JSON and pass it to a webmethod but id i want to use PageMethods? it even simpler - just pass the object as is [ WebMethod ] public static void AddPerson2( Person NewPerson) {    NewPerson.Add(); } public class Person {   public string FirstName { get ; set ; }   public string LastName { get ; set ; }   public string Address { get ; set ; }   public string City { get ; set ; }   public string State { get ; set ; }   public string Zip { get ; set ; }   public void Add()   {     // Magic happens here.   } } Client Side: var NewPerson = new Object(); NewPerson.FirstName = $( "#FirstName" ).val(); NewPerson.LastName = $( "#LastName" ).val(); NewPerson.Address = $(

JQuery Modal Dialog with Aspx Page Postback example

hi all! this is kinda the next part of this where i explain how to get a modal with ans aspx page in it http://bresleveloper.blogspot.co.il/2012/05/jquery-modal-dialog-with-aspx-page.html now i got into the part where i want to post the the secondary page but guess what? the response it the secondary page so i lose my main page, which is logical cuz the server doesnt keeps track for which page exactly i'm in but rather he gets a request and send the according resposne. so we cant use postback. nope, Response.End() isnt good either and always the page will be refreshed, u just cant not response the request. so the Dear God gave MS the wisdom of ajax! sais who that my form must be submitted? i can send an ajax request! here is how to ajax: http://bresleveloper.blogspot.co.il/2012/04/ajax-3-simle-ways.html so lets say i have at my main page a big story and if u want to subscribe i open a modal with an apsx page with all kinda stuff, (p.s. the $(func({...}); will work cuz

Join and Count from 1 table

what i initally wanted to do is that SELECT   _users.ID,         _users.FullName AS 'Name' ,          MAX (_users_logins.LastLogin ) AS 'Last Login' ,         COUNT (_users_companies.Company_ID)   AS 'No. of Costumers' ,          COUNT (_users_companies.Company_ID) AS 'No. of companies in talk' but u cant do it with joins purly cuz it will count the result so my good Chief Moshe tought me this SELECT  _users.ID,        _users.FullName AS 'Name' ,        _LOGINS.LastLogin AS 'Last Login' ,        _COMP.costumers AS 'No. of Costumers' ,        _TALKS.TALKS AS 'No. of companies in talk' FROM _users LEFT JOIN ( SELECT MAX( representative_logins.Login_Datetime ) AS LastLogin,            _users_logins.Rep_ID            FROM   _users_logins            GROUP BY Rep_ID) AS REP_LOGINS     ON _users.ID = REP_LOGINS.Rep_ID LEFT

Passing DataTable with Ajax from C# to JavaScript

answer is - u cant! but since ASP.NET WebMethod return Json we can do some things about WebMethods see http://bresleveloper.blogspot.co.il/2012/04/ajax-3-simle-ways.html the harder and smarter way is to serialize and de-serialize it but thats for next time, this post is for ANYBODY 1st thing 1st: DataRow is not serializeable so any doing with DataTable will be a mess so we create relevant class for them and into a list like that: [ WebMethod ] public static object GetDataTableJson() {    DataTable t =  MySqlDb .ExecuteSelect( "QUERY " );    return GetList(t); } public static List < MyDataRow > GetList( DataTable t) {    List < MyDataRow > l = new List < MyDataRow >();    foreach ( DataRow r in t.Rows)    {       l.Add( new MyDataRow ()       {