Showing posts from August, 2012

Simple Javascript Regex

some overview about what JS offer in terms of regex
more info about the use of RegExp object
and a simple example i found somewhere for PW check:

$(function () {
   $('#txtNewPW').keyup(function () {
      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 true and f will be false

Pass Complex Data / Class / Form to WebMethod with PageMethods / Ajax
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
publicstaticvoid AddPerson2(Person NewPerson)
  publicstring FirstName { get; set; }
  publicstring LastName { get; set; }
  publicstring Address { get; set; }
  publicstring City { get; set; }
  publicstring State { get; set; }
  publicstring Zip { get; set; }

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

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:

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 u return a DO…

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',

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
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:

publicstaticobject GetDataTableJson()
   DataTable t =  MySqlDb.ExecuteSelect("QUERY");
   return GetList(t);

publicstaticList<MyDataRow> GetList(DataTable t)
   List<MyDataRow> l = newList<MyDataRow>();
   foreach (DataRow r in