September 2009 - Posts

Jquery Live

I've got this scenario where i need to append html and every time you click more in append more of those to below.

now those html content Links which execute javascript function.

And to my surprise it does not trigger the click function.

So the Solution would be to use this $('linkclassname').live('click',function(){ //do something});

You bind it only once, The next /future Element Will be Bind the same Event , No need for recurring binding element

What is the difference between live and Bind?

as documentation on jquery

"When you bind a "live" event it will bind to all current and future elements on the page (using event delegation). For example if you bound a live click to all "li" elements on the page then added another li at a later time - that click event would continue to work for the new element (this is not the case with bind which must be re-bound on all new elements)"

 

implies that you set it once and all the same element will be bind the same.

So i give my link a class name and set the live on document ready.

Viola.. works

Share this post: | | | |
Posted by cipto with no comments
Filed under:

jquery(document.ready()) and updatepanel

When you use updatepanel . and your update panel partial post back to server. your jquery document ready won't be executed.

To Work around this we add another call to your logic after end request of requestmanager

It works like a charm

ex:Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                        function EndRequestHandler(sender, args) {
                            if (args.get_error() == undefined) {
                                DoOnload();


                            }
                        }

 Thanks to this article.

http://blog.dreamlabsolutions.com/post/2009/02/24/jQuery-document-ready-and-ASP-NET-Ajax-asynchronous-postback.aspx

 

Share this post: | | | |
Posted by cipto with no comments

UPNP

one alternative to foreward port is using UPNP. if your router support it then you can use simple program and library to forward port automatically

without someone open it for you, Universal plug and play support networking with protocol like tcpip,http,soap

http://www.codeproject.com/KB/IP/upnpnattraversal.aspx?msg=2706732

there's a library called mono .Nat that is deserved to have a look

http://projects.qnetp.net/wiki/mono-nat/API_Reference

 

 

Share this post: | | | |
Posted by cipto with no comments
Filed under:

How to make News link FB Like

The css you can copy from FB of course

currently using xslt as the template , remember to disable-output-escape ="yes" so that you cdata will treated as Tags not as text.

Read the Meta Tag , name description for  the quick headline words.

use the HTMLAgilePack . and load the string to htmlobject. and do a xpath to the meta

search for description

add the title as Href of link

 

Share this post: | | | |
Posted by cipto with no comments
Filed under:

FireWall C#

If you are building a Networking Application like i do. you will encounter how to add this things automatically, like adding application to firewall exception, and open the port on firewall,

get the firewall open port, etc.

First you need to add a reference to the Com : NetFwTypeLib.

Read here how to

Note that this person code, is not initiating the applications and ports Object , you will get message null/object reference not set on runtime.

here is how to initiate it and the complete code.

  static void AddThisApplicationToFirewallException()
        {
            Type TappClass= Type.GetTypeFromProgID("HNetCfg.FWAuthorizedApplication");

            INetFwAuthorizedApplication application = (INetFwAuthorizedApplication)Activator.CreateInstance(TappClass);

            if (!IsApplicationAddedAsExceptionToFirewall())
            {
                Console.WriteLine("Trying to add This Application Exception To FireWall");
                Logger.Write("Trying to add This Application Exception To FireWall", "ClientCategory");
                INetFwAuthorizedApplications applications;
                application.Name = "Tradix Client Console"; /*set the name of the application */
             
                string fullPath = System.IO.Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
                Console.WriteLine("Full Path of application :" +fullPath);
                Logger.Write("Full Path of application :" + fullPath, "ClientCategory");  
            
                application.ProcessImageFileName = fullPath;
                    /* set this property to the location of the executable file of the application*/
                application.Enabled = true; //enable it
                /*now add this application to AuthorizedApplications collection */
                Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
                INetFwMgr mgr = (INetFwMgr) Activator.CreateInstance(NetFwMgrType);
                applications = (INetFwAuthorizedApplications) mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;
                applications.Add(application);
                Console.WriteLine("Application :" + fullPath + " Added To FireWall Exception");
                Logger.Write("Application :" + fullPath + " Added To FireWall Exception", "ClientCategory");
                Console.ReadKey();
            }
        }

 static bool IsApplicationAddedAsExceptionToFirewall()
        {
            INetFwAuthorizedApplications applications;
            INetFwAuthorizedApplication application;

             Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
             INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
            applications = (INetFwAuthorizedApplications)mgr.LocalPolicy.CurrentProfile.AuthorizedApplications;
            var enumerate = applications.GetEnumerator();
            while (enumerate.MoveNext())
            {

            application = (INetFwAuthorizedApplication)enumerate.Current;
             if(application.Name.Equals("Your application Name"))
             {
                 return true;
             }
            }
            return false;

        }

private static List<INetFwOpenPort> openPortsByFireWall=new List<INetFwOpenPort>();
        private static void GetOpenPortByFireWall()
        {
            INetFwOpenPorts ports;
            INetFwOpenPort port;
            Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
            INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
            ports = (INetFwOpenPorts)mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts;
            //openPortsByFireWall.AddRange((IEnumerable<INetFwOpenPort>) ports);
            System.Collections.IEnumerator enumerate = ports.GetEnumerator();
            while (enumerate.MoveNext())
            {
                port = (INetFwOpenPort)enumerate.Current;
                openPortsByFireWall.Add(port);
            }

        }

  static void CheckIfPortIsAddToFirewallOrNot(int listeningPort)
        {
            Logger.Write("Checking listening Port is on the Firewall or not", "ClientCategory");
            Console.WriteLine("Checking listening Port is on the Firewall or not");
            Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
            INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
            INetFwOpenPorts ports=(INetFwOpenPorts)mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts;
            Type TportClass = Type.GetTypeFromProgID("HNetCfg.FWOpenPort");
            INetFwOpenPort port =(INetFwOpenPort)Activator.CreateInstance(TportClass);
            
                port.Port = listeningPort; /* port no */
                port.Name = "Your Application Name"; /*name of the application using the port */
                port.Enabled =  true; /* enable the port */
                
            /*other properties like Protocol, IP Version can also be set accordingly
            now add this to the GloballyOpenPorts collection */
           
            if (openPortsByFireWall.Where(c => c.Port.Equals(listeningPort)).FirstOrDefault() == null)
            {
                Console.WriteLine("Trying to add Port");
                Logger.Write("Trying to add Port", "ClientCategory");                 
                ports.Add(port);
                Console.WriteLine("Added Port");
                Logger.Write("Added Port", "ClientCategory");
            }
        }

 

 

 

Share this post: | | | |
Posted by cipto with no comments
Filed under: