[C#] Form close와 Dispose

.Net/C# 2013. 1. 28. 20:19

링크 (Form.Dispose) : http://msdn.microsoft.com/ko-kr/library/aw58wzka(v=vs.90).aspx

링크 (Form.Close) : http://msdn.microsoft.com/ko-kr/library/system.windows.forms.form.close(v=vs.90).aspx 


모달리스로 닫을시에는 Form.Close()를 호출

모달로 닫을시에는 Form.DialogResult 프로퍼티에 값을 대입

posted by 뚱2

[jQuery] ajaxForm 구현

JavaScript/jQuery 2012. 7. 23. 00:31

사실 ajax를 이용하는게 아니라 예전부터 많이 사용하던 iframe을 이용하여 화면 깜빡임을 없애는 방식이다.


/**

 * form을 ajax로 전송한다. (파일 포함)

 */

$.fn.ajaxForm = function(handler) {

    var $this = $(this);

    if ( $this[0] && $this[0].tagName.toUpperCase() == "FORM" ) {

        //랜덤한 수를 출력

        var ranNumber = Math.floor(Math.random() * 10000) + 1;

        var strId = "";

        strId += "SEED";

        strId += "_";    

        strId += (new Date()).getTime();

        strId += "_" + ranNumber;


        $this.attr("target", strId);    

        $("<iframe id=\"" + strId + "\" name=\"" + strId + "\" />")

            .hide()

            .appendTo($this.parents("body"))

            .load(function() {

                var that = this;


                if ( $.type(handler) == "function" ) {

                    var result = $.parseJSON(window.frames[strId].document.body.innerHTML);

                    if ( result == undefined || result == null || result == "" ) {

                        result = {

                            success : false,

                            message : "결과가 존재하지 않습니다."

                        };

                    }

                    handler(result);

                }

            });

    }//if ( $this[0] && $this[0].tagName.toUpperCase() == "FORM" ) {


    return $this;

};


사용방법

(function($, exports) {$(document).ready(function() {

////////////////////////////////////////////////////////////////////////////////////

$("#myform").ajaxForm(function(result) {

    if ( result && result.success == true ) {

        alert(result.message);

    }

});

////////////////////////////////////////////////////////////////////////////////////

});})(jQuery, window);



참고 : http://hanjiq.egloos.com/2373084 

posted by 뚱2

/**

 * obj  : url or json data

 * data : json data

 */

my.submitWithJson = function(obj, data, target, method) {

    try {

        var param = null;       

        // json object이라면

        if ( obj && Object.prototype.toString.call(obj) === '[object Object]' ) {

            param = {

                 'url'     : obj.url                 || ''

                ,'data'    : obj.data                || {}

                ,'target'  : obj.target              || '_self'

                ,'method'  : obj.method              || 'POST'

            };

        }

        else {

            param = {

                 'url'     : obj                     || ''

                ,'data'    : data                    || {}

                ,'target'  : target                  || '_self'

                ,'method'  : method                  || 'POST'

            }; 

        }

         

        //랜덤한 수를 출력

        var curDate   = new Date();

        var ranNumber = Math.floor(Math.random() * 10000) + 1;

        var strId = "";

            strId += param.target;

            strId += "_";           

            strId += curDate.getFullYear();

            strId += curDate.getMonth();

            strId += curDate.getDay();

            strId += curDate.getHours();

            strId += curDate.getMinutes();

            strId += curDate.getSeconds();

            strId += "_" + ranNumber;

             

        var $newForm = jQuery("<form></form>")

                        .attr("name"  , strId)

                        .attr("id"    , strId)

                        .attr("method", param.method);

        if ( $newForm ) {

            if ( Object.prototype.toString.call(param.data) === "[object Array]") {

                jQuery.each(param.data, function(index, val) {

                    var row = val;

                    jQuery.each(row, function(key, val) { 

                        jQuery("<input type='"hidden"'>")

                            .attr("name" , key)

                            .attr("value", val)

                            .appendTo($newForm);

                    });

                });

                $newForm.appendTo(document.body);

            }

            else {

                jQuery.each(param.data, function(key, val) { 

                    jQuery("<input type='"hidden"'>")

                        .attr("name" , key)

                        .attr("id"   , key)

                        .attr("value", val)

                        .appendTo($newForm);

                });

                $newForm.appendTo(document.body);               

            }

     

            var myForm = $newForm[0];

            myForm.action = param.url;

            myForm.method = param.method;

            myForm.target = param.target;

             

            myForm.submit();

            $newForm.remove();

        }//if ( $popForm ) {

    }

    catch (e) {alert(e.message);}

    finally   {}

}; 


posted by 뚱2

[jQuery] serialize()

JavaScript/jQuery 2011. 10. 17. 18:13
참고 : http://api.jquery.com/serialize/

폼객체의 엘리먼트들을 데이터 인코딩까지 해서 연결해주는 기능이다.
편한기능
posted by 뚱2