UpdataPanel 하위 컨트롤 찾기

.Net 2010. 11. 3. 17:32 posted by 무명시인
* UpdataPanel 속의 컨트롤 찾기

UpdataPanel 을 사용해서 내부의 컨트롤 개체들을 제어 할때..
그냥 UpdataPanel.컨트롤 개체로 찾으면 될줄 알았는데 아니었더군요..
복잡한것은 아니지만 조금 삽질 했습니다.^^;


    
    foreach (Control c in this.UpdatePanel1.ContentTemplateContainer.Controls)
    {
        // to do..
    }
    
    

jquery ajax 을 사용한 xml parsing

Js & Css/jQuery 2009. 12. 16. 09:46 posted by 무명시인
사용자 삽입 이미지



위 와같은 xml 을 jquery 로 분리를 해보자..

jquery 의 ajax 연동은 따로 설명 하지 않겠다. 아래 참고

http://docs.jquery.com/Ajax

	$.ajax({
		type: 'get'
		, dataType: "xml"
		, url: "Service.aspx"
		, data: "arg=L
		, success: function(xml) {
			// xml 노드 null 확인
			if ($(xml).find("list").find("item").length > 0) {

				// totalitem 찾기
				var totitem = $(xml).find("totalitem").text();
				
				// item 노드 loop
				$(xml).find("list").find("item").each(function(idx) {				
					
					var idx = $(this).find("idx").text()
					var title = $(this).find("title").text()
					var content = $(this).find("content").text()
					
				});
			}			
		}
		, error: function(xhr, status, error) {alert(error); }
	});


ajax 를 콜한이후에.. xml 개체가 넘어온다.
최상위 노드가 "list" 이기 때문에
jquery 의 find 메소드로 "list" 노드를 찾고
totalitem 값(.text() 메소드 사용) 을 찾고..
"item" 노드를 찾아서
반복(.each 메소드 사용) 에서 "item" 노드 의 값들을 분리 하면된다.
여기서 .each 메소드 내부에서 $(this) 개체는 "item" 노드 이다.


PageLoading

Ajax Extension 2009. 4. 28. 09:10 posted by 무명시인
사용자 삽입 이미지


위 그림처럼 페이지 로딩바를 만들어보자..

사용자 삽입 이미지


기본적으로 Ajax Extension 의 UpdateProcess 를 사용하고.

(1) Doctype 을 제거.. 스타일을 위해..

(2) UpdateProcess 의 첫번째 Div 돌아가는 gif 이미지..배경을 하얗게..

(3) 배경을 회색으로 만드는 Div.. 스타일에 주목하자..



사용자 삽입 이미지


.cs 에서는 확인용 3초 딜레이..


" $ " 키워드

Ajax Extension 2009. 4. 6. 17:34 posted by 무명시인


<script type="text/javascript" language="javascript">
	document.getElementById('개체명')  =  $get("개체명");
</script>


$ 키워드는 해당 개체를 가져온다 ..

ScriptManager 가 올려져 있는 aspx 페이지에서 사용할수 있다.


<script type="text/javascript" language="javascript">
	$get("Label1").innerHTML = $get("TextBox1").value;

	document.getElementById('Label1').innerHTML = document.getElementById('TextBox1').value
</script>


결국 위 아래 구문은 같다.

Javascript 사용

Ajax Extension 2009. 4. 6. 15:18 posted by 무명시인


[msdn 참고 경로]

asp.net 에서 자바스크립트를 사용할때 다음메소드를 사용한다.


public static void RegisterClientScriptBlock(
    Control control,
    Type type,
    string key,
    string script,
    bool addScriptTags
)

public static void RegisterClientScriptBlock(
    Page page,
    Type type,
    string key,
    string script,
    bool addScriptTags
)


두개의 overload method..

다른건 실행 주체가 컨트롤(Update Panel 포함) 이냐..

Page 개체이냐의 차이다..

아래는 쌤플코드..


ScriptManager.RegisterClientScriptBlock(
            업데이트 패널 개체
            , this.GetType()
            , "jsAlert"
            , "<script type="text/javascript" language="javascript">alert('111');</script >"
	    , false);

ScriptManager.RegisterClientScriptBlock(            
	    this.Page            
	   , this.GetType()            
	   , "jsAlert"            
	   , "<script type="text/javascript" language="javascript">alert('111');</script >"
	   , false);


Timer

Ajax Extension 2009. 4. 6. 15:10 posted by 무명시인



                                
                

                
                
    <title>??</title>

                













                
                
<body>
    
<%=DateTime.Now.ToString()%> </body>


Ajax Extension 의 타이머 컨트롤이다 ..

일정한 주기로 페이지 로드를 하는 컨트롤이다 ..

Interval 속성에 일정주기를 설정해주면 된다 ..

ex) 1000 -> 1초


[Ajax] 파일 다운로드

.Net 2009. 1. 9. 14:26 posted by 무명시인

//파일다운로드
function fileUrl(fileUrl) {

    //요청 URL + 입력텍스트 값
    var Url = "BBC001D.aspx?Checkform=FileOpen&param=" + fileUrl;
   
    //XML Request 객체 선언및 Open
    var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
    xmlRequest.open("POST", Url, false);

    //헤더값 설정
    xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    //요청
    xmlRequest.send(null);

    if (xmlRequest.ResponseText == "false") {
        alert("파일이 존재하지 않습니다.");
        return false;
    }
    __doPostBack('lnkBtnShow', '');
    location.href = xmlRequest.ResponseText;
   
}

#region ## Page_Load ##

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Checkform"] == null) return;

        string strCheckform = Request.QueryString["Checkform"].ToString();
        string strStrID = Request.QueryString["param"].ToString();

        if (strCheckform.ToString().Equals("FileOpen")) FileCheck(strStrID);
    }

    #endregion

    #region ## FileCheck ##

    /// <summary>
    /// 파일 다운로드
    /// - 작  성  자 : 최성춘 (주)정원엔시스템
    /// - 최초작성일 : 2008.10.30
    /// - 최초수정자 :
    /// - 최초수정일 :
    /// - 주변경로그 :
    /// - 작업  내용 :
    /// </summary>
    private void FileCheck(string strStrID)
    {
        string[] strBoard = strStrID.ToString().Split('|');

        BBC001S obj = new BBC001S();

        DataSet ds = obj.GetBoardFileSelect(strBoard);

        bool blnFileExists = File.Exists(Server.MapPath(ds.Tables[0].Rows[0]["FilePath"].ToString()));

        if (blnFileExists)
        {           
            string[] arrExt = ds.Tables[0].Rows[0]["FilePath"].ToString().Split('.');

            if (arrExt[1].ToString().ToLower().Equals("gif")
                || arrExt[1].ToString().ToLower().Equals("jpg"))
            {
                Response.Redirect(ds.Tables[0].Rows[0]["FilePath"].ToString());
            }
            else
            {
                Response.Write(ds.Tables[0].Rows[0]["FilePath"].ToString());
            }

            Response.Flush();
            Response.End();           
        }
        else
        {       
            Response.Write("false");                       
            //Response.Redirect("Default.aspx");
        }
    }

    #endregion


아작스 포스트로 화일정보 넘겨주고 뿌려주기

http://msdn.microsoft.com/ko-kr/library/system.web.ui.icallbackeventhandler(VS.80).aspx

.NET Framework 클래스 라이브러리
ICallbackEventHandler 인터페이스

참고: 이 인터페이스는 .NET Framework 버전 2.0에서 새로 추가되었습니다.

컨트롤이 서버에 대한 콜백 이벤트 대상이 될 수 있음을 나타내는 데 사용됩니다.

네임스페이스: System.Web.UI
어셈블리: System.Web(system.web.dll)

C#
public interface ICallbackEventHandler

콜백 이벤트를 수신해야 하는 사용자 지정 컨트롤에 대해 ICallbackEventHandler 인터페이스를 구현합니다. 자세한 내용은 ASP.NET 웹 페이지에서 다시 게시하지 않는 클라이언트 콜백 구현을 참조하십시오.

ICallbackEventHandler 인터페이스를 구현하는 컨트롤의 예로는 GridView, DetailsViewTreeView 컨트롤이 있습니다. ICallbackEventHandler 인터페이스를 구현하는 컨트롤이 콜백 이벤트의 대상이 되는 경우, RaiseCallbackEvent 메서드가 호출되어 이벤트를 처리하고 이벤트 인수를 매개 변수로 전달하며 GetCallbackResult 메서드는 콜백의 결과를 반환합니다.

콜백을 수행하는 동안 데이터 소스 컨트롤에서 데이터를 검색하는 컨트롤은 이 작업을 동기적으로 또는 비동기적으로 수행할 수 있습니다. GridView, DetailsViewTreeView 같은 ASP.NET 컨트롤은 동기적으로 구현됩니다. 비동기 프로그래밍에 대한 자세한 내용은 비동기 프로그래밍 디자인 패턴을 참조하십시오.

ICallbackEventHandler 인터페이스를 구현하는 컨트롤에 의해 렌더링된 사용자 인터페이스에서 콜백 이벤트가 발생할 경우 이 이벤트의 유효성을 검사할지 여부를 지정할 수 있습니다. 이벤트의 유효성 검사는 보안을 위해 유용한 방법입니다. 그러나 성능상의 이유로 이 기능을 사용하지 않을 수 있습니다. 콜백 이벤트에 대해 이벤트 유효성 검사를 수행할지 여부를 제어하려면 @ Page 지시문의 enableEventValidation 특성이나 Web.config 파일에 있는 pages 요소(ASP.NET 설정 스키마)enableEventValidation 특성을 설정합니다. 코드에서 EnableEventValidation 속성을 설정할 경우 페이지 처리의 Page_Init 단계에서 설정합니다. 이벤트 유효성 검사의 보안 장점과 성능 저하 사이의 관계를 적절하게 조정하는 방법에 대한 자세한 내용은 고성능 ASP.NET 응용 프로그램 개발을 참조하십시오.


이상 엠수디엔 설명..
구구 절절이 길게 어려운 말 투성인데..
아즈악스 의 사돈의 팔촌 처럼..
비동기 기능을 구현 한다는 예기 이더라..
엠수 디엔을 참고 해서 다음 아티클에 간단한 예제들..

[.Net] Ajax 해보자

.Net 2008. 7. 3. 17:51 posted by 무명시인



0. 웹사이트 플젝을 생성하자.


1. 우선은 첨부한 AJAX.dll 을 Bin 폴더에 붙여 넣자.

2. Web.Config 에 다음 줄을 추가 하자.

<system.web>
      <httpHandlers>
        <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
      </httpHandlers>
</system.web>

3. Page_Load 에 다음 추가.

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {       
        Ajax.Utility.RegisterTypeForAjax(typeof(_Default));
    }
}

4. 인서트를 하는 디비 메서드를 추가 한다. 주의 !!상단[Ajax.AjaxMethod] 꼭!!

using System.Data.SqlClient;
.....

[Ajax.AjaxMethod]
    public int Insert(string str1, string str2)
    {
        string strQuery
            = String.Format(
            "INSERT TEST(title, content) VALUES('{0}', '{1}')", str1, str2);
        string strConnectionString
            = "server=.;database=test;uid=sa;pwd=???;";

        SqlConnection con = new SqlConnection(strConnectionString);
        SqlCommand cmd = new SqlCommand(strQuery, con);
        cmd.CommandType = CommandType.Text;

        con.Open();
        int intResult = cmd.ExecuteNonQuery();
        con.Close();

        return intResult;
    }

5. *.aspx 부분

<script type="text/javascript" language="javascript">      
       
        function InsertDB()
        {
            var str1=document.all["txt1"].value;
            var str2=document.all["txt2"].value;
           
            document.all["div1"].innerText=  _Default.Insert(str1,str2).value;            
        }
</script>

<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<asp:TextBox ID="txt2" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="InsertDB(); return false;" />
        <div id="div1">
        </div>

6. 실행..

  디비에 값이 입력되는것을 확인~~

  포스트 빽이 일어나지않고 동작~~

7. 참고~~

http://ajax.schwarz-interactive.de/csharpsample/default.aspx