posted by 써니루루 2007. 6. 8. 13:08
원문 : http://www.microsoft.com/korea/msdn/library/windows/issues/2003/ws03perfbench/default.aspx

기존 ASP에서의 Session은 In-Process의 세션만을 사용하였고 이 때문에 개별적인 세션을 사용하기 힘들었습니다.
ASP.NET에서는 Out of process session인 'ASPState'로 서비스에 등록되어 있는 State server를 이용하여 세션을 관리해야하는 이유가 이것 때문입니다.
아래는 위 원문에서 발췌한 내용입니다.


클러스터에서 세션 개체를 사용할 수 있는 기능. 장바구니는 클러스터에서 사용 가능해야 하므로 세션 개체를 사용하여 ASP에서 장바구니를 구현할 수 없습니다. ASP를 사용하면 세션 개체는 웹 서버와 함께 항상 in-process이며 여러 웹 서버는 사용자를 해당 고유한 장바구니에 다시 매핑할 수 없습니다. 클라이언트 선호도를 사용할 수 있지만 서버가 다운되거나 클러스터에 추가될 때 장애 조치 상태가 여전히 작동하지 않을 것이며 일부 사용자 세션 상태는 손실될 것입니다. 하지만 ASP.NET을 사용하면 이러한 제한은 더 이상 적용되지 않습니다. in-process에서 중앙 전용 상태 서버로 또는 중앙 RDBMS 데이터베이스로 세션 개체를 쉽게 매핑할 수 있습니다. 따라서 ASP.NET 버전은 세션 개체를 사용하여 각 사용자에 대한 장바구니를 저장합니다. 장바구니는 네트워크를 통해 전달하거나 데이터베이스에 기록할 수 있도록 serializable로 표시됩니다. 클러스터에 사용할 수 있으려면 ASP 버전이 사용자 지정 데이터베이스 처리 루틴에서 장바구니를 구현해야 합니다.
posted by 써니루루 2007. 5. 27. 19:29
Gmail Form

Gmail Form


말은 상당히 거창하다 - _-;;

참고 주소는 http://aspalliance.com/867 요기를 보면되며..

사실 .NET을 해본  사람이라면 .NET에서 제공하는 SMTP메일 클라이언트를 이용해서 메일을 보내는 소스코드가 얼마나 간단히 나오는지 알 것이다.

이 예제도 마찬가지로 상당히 짧은 코드지만 Gmail의 SMTP를 이용해보려고 삽질(?)한 노력이 보일것이다;

하지만 결론부터 얘기하자면 실패했다는것 ㅠㅠ

Google Mail의 기본 SMTP 포트는 465로 되어있는 것을 확인했다.

하지만 메일이 전송되지 않길래 무슨문젤까 하고 google.com의 검색으로 외국을 긁어나가기 시작했다..

포트를 587로 바꾸라고? -_ -;;

바꿔서도 해봤다..

안된다 ㅠㅠ

누가 해결하신분은 도움을 주시길..

물론 gmail의 smtp를 안쓰고 로컬에 있는 iis의 smtp를 이용하면 간단히 해결되는 문제지만;;

목적이 gmail의 smtp를 훔쳐쓰는 것이기에 -ㅁ-;; ㅋㅋ

아래는 본인이 삽질(?)한 소스코드이다~

less..

 


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Google Form Mailer</title>
</head>
<body>
    <form id="GMailForm" runat="server">
    <div>
   
    <table style="border-collapse:collapse;" width="400" cellpadding="5" cellspacing="0">
        <tr>
            <th colspan="2">
            Google Form mail
            </th>
        </tr>
        <tr>
            <td style="width: 150px; text-align: right">
                E-mail to :
           
            </td>
            <td>
                <asp:TextBox ID="txtMailTo" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td style="width: 150px; text-align: right">
                Subject :</td>
            <td>
                <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td style="width: 150px; text-align: right">
                Contents :
            </td>
            <td>
                <asp:TextBox ID="txtContents" runat="server" Rows="5" TextMode="MultiLine"></asp:TextBox></td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <asp:Button ID="btnMailSend" runat="server" OnClick="btnMailSend_Click" Text="Send mail" /></td>
        </tr>
    </table>
   
    </div>
    </form>
</body>
</html>




Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Net;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    /// <summary>
    /// E-mail Message class
    /// </summary>
    private MailMessage Mail = null;

    /// <summary>
    /// Network base authentication
    /// </summary>
    private NetworkCredential AuthInfo = null;

    /// <summary>
    /// SMTP Mail Sender
    /// </summary>
    private SmtpClient Smtp = null;

    /// <summary>
    /// Email address
    /// </summary>
    private string sMailFrom = "";

    /// <summary>
    /// smtp login id
    /// </summary>
    private string sLoginID = "";

    /// <summary>
    /// smtp login password
    /// </summary>
    private string sLoginPass = "";

    /// <summary>
    /// Default Page load script
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        sMailFrom = "sunyruru@gmail.com";
        sLoginID = "sunyruru";
        sLoginPass = "****";
    }

    /// <summary>
    /// Mail Send button event script
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnMailSend_Click(object sender, EventArgs e)
    {
        // Email message set
        Mail = new MailMessage(sMailFrom, txtMailTo.Text.Trim());
        Mail.Subject = txtSubject.Text;
        Mail.Body = txtContents.Text;


        // Authentication to SMTP Service
        AuthInfo = new NetworkCredential(sLoginID.Trim() + "@gmail.com", sLoginPass.Trim());

        // SMTP Sender
        Smtp = new SmtpClient();

        try
        {
            Smtp.Host = "smtp.google.com"; // SMTP Host
            Smtp.Port = 465; // SMTP Port
            Smtp.UseDefaultCredentials = false;
            Smtp.Credentials = AuthInfo;
            Smtp.EnableSsl = true; // Use SSL Secure connection

            Smtp.Send(Mail); // Send email message
        }
        catch (System.Net.Mail.SmtpFailedRecipientsException ex) { PrintError(ex.Message); }
        catch (System.Net.Mail.SmtpException ex) { PrintError(ex.Message); }
        catch (ObjectDisposedException ex) { PrintError(ex.Message); }
        catch (InvalidOperationException ex) { PrintError(ex.Message); }
        catch (ArgumentNullException ex) { PrintError(ex.Message); }
        catch (ArgumentOutOfRangeException ex) { PrintError(ex.Message); }
        catch (ArgumentException ex) { PrintError(ex.Message); }
        catch (Exception ex) { PrintError(ex.Message); }
    }

    /// <summary>
    /// Javascript error message popup
    /// </summary>
    /// <param name="ErrorMessage"></param>
    protected void PrintError(string ErrorMessage)
    {
        Response.Write("<script>\n");
        Response.Write("alert('" + ErrorMessage + "')");
        Response.Write("</script>\n");
    }
}



less..


귀차니즘이 있으시다면...

아래 압축파일로 ;;

RURU_test_Mail_GmailSmtp.zip

ASP.NET 웹페이지

posted by 써니루루 2007. 5. 22. 23:17
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(0));
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetValidUntilExpires(true);
        Response.Cache.SetNoServerCaching();

브라우져의 페이지가 자주 바뀌는 페이지는 브라우져 캐쉬를 무효화 해야할 경우가 생긴다.

이런 때에는 Page_Load 부분에 위와 같은 구문을 넣어보자..

posted by 써니루루 2007. 5. 22. 17:04

Out-of-process Mode

Included with the .NET SDK is a Windows® NT service: ASPState. This Windows service is what ASP.NET uses for out-of-process session state management. To use this state manager, you first need to start the service. To start the service, open a command prompt and type:

net start aspstate

What you'll see is:

Figure 1. Starting the Windows NT service ASPState at the command prompt

At this point, the Windows NT Service ASPState has started and is available to ASP.NET. Next, we need to configure ASP.NET to take advantage of this service. To do this we need to configure config.web:

<configuration>
  <sessionstate 
      mode="stateserver"
      cookieless="false" 
      timeout="20" 
      sqlconnectionstring="data source=127.0.0.1;user id=<user id>;password=<password>"
      server="127.0.0.1" 
      port="42424" 
  />
</configuration>

We changed only from inproc mode to stateserver mode. This setting tells ASP.NET to look for the ASP state service on the server specified in the server and port settings—in this case, the local server.

We can now call SessionState.aspx, set a session state value, stop and start the IIS process (iisreset), and continue to have access to the values for our current state.

posted by 써니루루 2007. 5. 16. 16:05

<%@ Control Language="C#" ClassName="postImage" %>
<%@ Import Namespace="System.IO" %>


<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile == true)
        {
            string upDir = Server.MapPath(".") + "\\upload\\";
           
            DirectoryInfo di = new DirectoryInfo(upDir);
            if (di.Exists == false)
                di.Create();

            string fName = FileUpload1.FileName;
            string fFullName = upDir + fName;
            FileInfo fInfo = new FileInfo(fFullName);

            if (fInfo.Exists == true)
            {
                int findex = 0;
                string fExt = fInfo.Extension;
                string fRealName = fName.Replace(fExt, "");

                string newFileName = "";
                do
                {
                    findex++;
                    newFileName = fRealName + "_" + findex.ToString() + fExt;
                    fInfo = new FileInfo(upDir + newFileName);
                } while (fInfo.Exists);

                fFullName = upDir + newFileName;
                fName = newFileName;
            }

            FileUpload1.PostedFile.SaveAs(fFullName);
            fInfo = new FileInfo(fFullName);

            Panel1.Visible = true;
            lblMessage.Text = "업로드 된 파일 : " + fFullName + "\n<br />";
            /*lblMessage.Text += "업로드 사이즈 : "
                + Convert.ToString(int.Parse(Convert.ToString(float.Parse(fInfo.Length.ToString()) / 1024.0f)))
                + "KB";*/
            Image1.ImageUrl = "../upload/" + fName;
            HiddenField1.Value = "upload/" + fName;
        }
        else
        {
            Panel1.Visible = true;
            lblMessage.Text = "업로드 할 파일이 존재하지 않습니다.";
        }
    }

</script>


<div class="titleText">이미지를 등록해주세요</div>
<br />
<div class="noticeText">* 이미지는 명함, 반명함 사진으로 확장자는<br /> gif, jpg, png 등으로만 올려주시기 바랍니다.</div>
<br />
<div id="fileImage">
    <asp:FileUpload ID="FileUpload1" runat="server" Width="200px" />&nbsp;<br />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="사진 파일 올리기" /><br />
</div>
<p></p>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="298px" Visible="False">
    <asp:Label ID="lblMessage" runat="server"></asp:Label><br />
    <asp:Image ID="Image1" runat="server" Width="130" /><br /><br />
    </asp:Panel>
<asp:HiddenField ID="HiddenField1" runat="server" />


간단하게 만들었던 이미지 업로드 컨트롤 *.ascx 파일로 만들어두면 편하다.

참 급조로 만든거라 상당히 부실한 -_ -;;;

요래 코딩하면 안되는뎅;;

반성 반성~


만약에 업로드하는 부분만 메소드로 뺀다면 ...

    /// <summary>
    /// 이미지를 업로드 한 후 저장된 파일 경로를 반환한다.
    /// </summary>
    /// <param name="FileUp">업로드 컨트롤</param>
    /// <param name="SubCode">과목코드</param>
    /// <returns></returns>
    protected string ImageUpload(FileUpload FileUp, int SubCode)
    {
        string ret = "";        // 반환할 문자열
        string upDir = "";      // 업로드할 파일 저장 위치
        string fName = "";      // 업로드된 실제 파일명
        string fFullName = "";  // 저장할 파일의 풀 경로
        string fExt = "";       // 파일의 확장자명
        string fRealName = "";  // 파일의 확장자를 뺀 실제 파일명
        string newFileName = "";// 새로 만들어질 파일명

        int findex = 0; // 파일의 인덱스번호
       
       
        System.IO.DirectoryInfo di = null;
        System.IO.FileInfo fInfo = null;
       
        // 파일이 있나?
        if (FileUp.HasFile == true)
        {
            // 저장할 경로
            upDir = Server.MapPath("..") + "\\upload\\exam\\" + SubCode.ToString();
           
            // 경로에 디렉토리가 없으면 만든다.
            di = new System.IO.DirectoryInfo(upDir); // 디렉토리를 다룰 연장
            if (di.Exists == false)
                di.Create();

            // 업로드 된 파일을 가지고 저장할 파일의 풀 경로를 만들어낸다.
            fName = fileup.FileName;
            fFullName = upDir + fName;
            fInfo = new System.IO.FileInfo(fFullName); // 파일을 다룰 연장

            // 이미 해당하는 파일이 있으면
            if (fInfo.Exists == true)
            {
                fExt = fInfo.Extension;
                fRealName = fName.Replace(fExt, "");

                // 루프를 돌면서 실제 저장될 파일명을 결정한다.
                do
                {
                    findex++;
                    newFileName = fRealName + "_" + findex.ToString() + fExt;
                    fInfo = new System.IO.FileInfo(upDir + newFileName);
                } while (fInfo.Exists);

                fFullName = upDir + newFileName;
                fName = newFileName;
            }

            FileUp.PostedFile.SaveAs(fFullName);
            fInfo = new System.IO.FileInfo(fFullName);

            ret = "../upload/" + fName;
        }
       
        return ret;
    }

posted by 써니루루 2007. 3. 19. 20:08

먼저 FarPoint Technologies' Spread 6를 설치하셔야 이 예제를 해보실 수 있습니다.
ActiveX 작성한 IDE 툴로는 VB 6.0을 이용하였습니다.

먼저 VB 6.0의 새프로젝트를 열고 'ActiveX 사용자 정의 컨트롤' 프로젝트를 만듭니다.

프로젝트 속성

프로젝트 이름과 컨트롤의 이름을 다음과 같이 작성한다.



먼저 프로젝트명과 컨트롤의 속성에서 이름을 각각 AXSS와 SS로 지정하였다.

FarPoint Spread(OLEDB)

VB 6.0의 도구모음에서 '마우스 우클릭'을 해서 '구성 요소'를 선택해 위와같이 Spread 6 'FarPoint Spread(OLEDB)' 를 추가해주자.


VB 6.0의 도구모음에서 '마우스 우클릭'을 해서 '구성 요소'를 선택해 위와같이 Spread 6 'FarPoint Spread(OLEDB)' 를 추가해주자.

컨트롤 패널위에 fpSpread

'MaxCols'와 'MaxRows'를 각각 1로 설정


등록된 버튼 2개중 좌측에 있는 버튼을 클릭해서 컨트롤 패널위에 fpSpread를 끌어다 놓고,
속성 중 'MaxCols'와 'MaxRows'를 각각 1로 설정해서 한칸만 나타나도록 설정하였다.

스프레드 화면

화면에 1 * 1의 스프레드가 뜨는 것을 확인할 수 있다.


위와 같이 화면에 1 * 1의 스프레드가 뜨는 것을 확인할 수 있다.

Spread 이름

Spread 이름을 'SS1'으로 변경하였다.


추가된 스프레드의 이름은 'SS1' 이라고 이름을 변경해 주었다.

프로젝트에서 컨트롤에 우클릭해서 '코드보기'를 클릭해 코드보기 모드로 들어가서 다음 파일의 소스 코드를 입력한다.


코드를 다 입력하고 나면


압축파일의 압축을 풀고, 파일들을 프로젝트의 폴더로 옮겨서 프로젝트에서 기존 파일을 추가해서 SubMain.vb 파일을 프로젝트에 추가시키고,

tlb파일 참조

프로젝트 메뉴의 '참조'를 클릭해 tlb 파일을 추가해 보자


프로젝트 메뉴의 '참조'를 클릭해 tlb 파일을 추가해 보자


참조가 추가된 모습

참조가 추가된 모습 - VB6 - IObjectSafety Interface가 보일 것이다.


참조가 추가된 모습 - VB6 - IObjectSafety Interface가 보일 것이다.

프로젝트 속성

프로젝트 속성 메뉴에 들어가서 시작 개체를 'Sub Main'으로 바꿔준다



프로젝트 속성 메뉴에 들어가서 시작 개체를 'Sub Main'으로 바꿔준다.


이제 단축키 F5를 눌러 브라우져가 실행되는 것을 확인해보자..

사용자 삽입 이미지

다음과 같이 브라우져 상에서도 컨트롤이 뜨는 것을 확인할 수 있다.

우선 이렇게 해서 ActiveX가 되는것을 확인했으니 반은 다 된샘이 아닐까?

그렇다고..

창을 닫아 버리고 끝까지 보지 않으면 -_ -;; ActiveX를 제대로 배포하거나 사용한다고 할 수 없다.


File 메뉴의 OCX 만들기

File 메뉴의 OCX 만들기를 클릭해서 해당 폴더에 ocx파일을 만들어보자


먼저 File 메뉴의 OCX 만들기를 클릭해서 해당 폴더에 ocx파일을 만들어보자.

ocx 파일이 만들어졌으면 이 ocx 파일을 가지고 배포 패키지를 만들어야 한다.

추가 기능 관리자

추가 기능 관리자 > 패키지 및 배포 마법사의 '로드/언로드', '시작할 때 로드'를 체크해준다.


추가 기능 관리자 > 패키지 및 배포 마법사의 '로드/언로드', '시작할 때 로드'를 체크해준다.

이제 '패키지 및 배포 마법사' 메뉴가 활성화 되어있을 것이다.

패키지 및 배포 마법사

패키지 및 배포 마법사


패키지 메뉴를 클릭한다.

패키지 형식

패키지 형식은 '인터넷 패키지'를 선택한다.



패키지 형식은 '인터넷 패키지'를 선택한다.


패키지 폴더

패키지 폴더는 그냥 다음을 눌러서 넘어가면 'Package' 폴더가 생성되는걸 확인한다.



패키지 폴더는 그냥 다음을 눌러서 넘어가면 'Package' 폴더가 생성되는걸 확인한다.


포함된 파일

다음으로 넘어오면 종속성 창이 뜨는데 체크를 전부 하지 말고 다음으로 넘어가자



다음으로 넘어오면 종속성 창이 뜨는데 체크를 전부 하지 말고 다음으로 넘어가자.

파일 원본

'파일 원본' 창에서 '이 Cab 파일에 포함'을 체크하고 다음으로 넘어가자.


'파일 원본' 창에서 '이 Cab 파일에 포함'을 체크하고 다음으로 넘어가자.

안전 설정

'안전 설정'에서 '스크립트 사용에 안전'과 '초기화에 안전' 둘다 '예'로 변경하자.


'안전 설정'에서 '스크립트 사용에 안전'과 '초기화에 안전' 둘다 '예'로 변경하자.

완료

'완료'창이 떴으니 이제 패키지는 만들어 졌다고 보면 된다.


'완료'창이 떴으니 이제 패키지는 만들어 졌다고 보면 된다.
기본으로 설정된 '인터넷 패키지 1'으로 하고, *.cab 파일이 생성된 것을 확인하자.



위 압축 파일을 프로젝트 폴더에 받아 압축을 풀면 2개의 폴더가 생성된다.

versign 폴더에서 *.bat 파일이 2개 있는데 편집모드로 열어보면 이름을 바꿀 수 있다.

Versign

Versign


먼저 MakeSign.bat 파일을 실행하면,

암호 만들기

암호 만들기

위와 같이 암호를 설정할 수 있다.

암호는 까먹지 않도록 잘 기억하고, 암호를 입력한다.

사용자 삽입 이미지

파일이 AXSS로 2개가 형성된 것을 볼 수 있고,
MakeSpc.bat 파일을 마저 실행하면,

파일 3개

파일 3개


다음과 같이 총 3개의 파일을 볼 수 있다.

사용자 삽입 이미지


압축을 해제할때 있던 다른 폴더를 가보면 *.exe 실행파일을 실행해보자.
아까 빌드를 했으니 아마 위 그림과 같이 AXSS.SS 가 좌측에 추가된 것을 볼 수 있다.
추가 버튼을 눌러 오른쪽에 나타나도록 하고 'Save & Exit' 버튼을 눌러서,

사용자 삽입 이미지

다음과 같이 lpk 파일을 저장한다.

파일복사

lpk 파일과 signcode.exe 파일 복사


만들어진 lpk파일과 signcode.exe 파일을 cab파일이 만들어진 폴더로 복사해서 같은 폴더에 위치시키도록 하자.

signcode.exe 실행

signcode.exe 실행



signcode.exe 실행하면 다음과 같은 창이 뜬다. 다음을 클릭한다.

cab파일 선택

확장자를 cab으로 변경하고 cab파일을 선택한다.

확장자를 cab으로 변경하고 cab파일을 선택한다.

사용자 지정

사용자 지정을 클릭하고 다음을 넘어간다.

사용자 지정을 클릭하고 다음을 넘어간다.

인증서 파일 선택

인증서 파일을 선택한다.


인증서 파일을 선택한다.

사용자 삽입 이미지

찾아보기를 클릭해서 개인키 파일을 다음과 같이 설정한다.

사용자 삽입 이미지


해시 알고리즘

해시 알고리즘


해시 알고리즘은 'sha1'을 골라주고 다음을 클릭한다.

cab파일 인증

인증 완료.


이제 cab파일의 디지털 인증은 완료되었다. 마침을 클릭하자.

사용자 삽입 이미지

위와 같이 아름다운(?) 메시지를 확인할 수 있다.

사용자 삽입 이미지

이제 위에 생성된 cab 파일을 이용해서 activex를 자바스크립트와 HTML 컨트롤을 이용해서 제어하는 코드를 작성해보자.

기본적으로 text 에디터로 html 파일을 열어보면,


위 텍스트 파일처럼 작성이 되어 있을 것이다.

이제 우리는 HEAD 테그 엘레먼트아래 SCRIPT 테그 엘레먼트를 추가해서 ACTIVEX 제어코드와 HTML INPUT 컨트롤로 TEXT, BUTTON을 각각 2개 추가하고,

ACTIVEX에 이미 작성되어 있던 메소드를 호출해 볼 것이다.


위 HTML 코드를 다음 코드로 변경 시키도록 하자.
(OBJECT 테그에 있는 내용은 각자 작성된 HTML 코드로 이용한다.)

사용자 삽입 이미지

이제 다음과 같이 웹페이지 안에 ACTIVEX 컨트롤이 뜨는 것을 확인 할 수 있고,

위쪽의 텍스트 상자에 값을 입력하고 첫번째 버튼을 클릭하면 Spread 안에 값이 입력되고,
스프레드의 1, 1 위치에 값을 입력한 후 두번째 버튼을 클릭하면 Spread 안의 값을 테그트 상자에 가져오는 것을 확인 할 수 있다.

본 강좌에서 사용한 전체 파일의 압축 파일은 아래 파일을 다운받으면 볼 수 있다.


이상으로 FarPoint Spread를 이용한 ActiveX 페이지와 스크립트 제어에 대한 강좌를 마친다.




Creative Commons License
저작물크리에이티브 커먼즈 코리아 저작자표시-비영리-동일조건변경허락 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
posted by 써니루루 2007. 3. 10. 21:47

출처 : 뇌를 자극하는 ASP.NET


ASP.NET에서 제공하는 달력을 쉽게 만들 수 있는 컨트롤 입니다.



<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> Calendar </title>
   
    <script runat="server">
       
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 바뀌면 날짜선택을 초기화한다.
            Calendar1.SelectionMode = (CalendarSelectionMode)DropDownList1.SelectedIndex;
           
            if(Calendar1.SelectionMode == CalendarSelectionMode.None)
                Calendar1.SelectedDates.Clear();
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            switch (Calendar1.SelectedDates.Count)
            {
                case 0: // None
                    Response.Write("어떤 일자도 선택되지 않았습니다.");
                    break;
                case 1: // Day
                    Response.Write("선택한 일자"
                        + Calendar1.SelectedDate.ToShortDateString()
                    );
                    break;
                case 7: // Week
                    Response.Write("선택한 주의 시작 일자"
                        + Calendar1.SelectedDate.ToShortDateString()
                    );
                    break;
                default: // Month
                    Response.Write("선택한 달의 시작 일자"
                        + Calendar1.SelectedDate.ToShortDateString()
                    );
                    break;
            }
        }

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            CalendarDay d = e.Day;
            TableCell c = e.Cell;

            if (d.IsOtherMonth)
            {
                c.Controls.Clear();
            }
            else
            {
                string message = GetSchedule(d.Date.Month, d.Date.Day);
                c.Controls.Add(new LiteralControl("<br />" + message));
            }
        }

        string GetSchedule(int month, int day)
        {
            string schedule = "";

            if (month == 3 && day == 14)
            {
                schedule = "<a href='http://www.naver.com'>화이트데이</a>";
            }
            else if (month == 3 && day == 1)
            {
                schedule = "3.1절";
            }

            return schedule;
        }
</script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <h3>Calendar의 SelectionChange의 이벤트를 사용하는 예제</h3>
       
        <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="None">None</asp:ListItem>
            <asp:ListItem Value="Day" Selected="True">Day</asp:ListItem>
            <asp:ListItem Value="DayWeek">DayWeek</asp:ListItem>
            <asp:ListItem Value="DayWeekMonth">DayWeekMonth</asp:ListItem>
        </asp:DropDownList>
       
        <br />
       
        <asp:Calendar ID="Calendar1" runat="server" Width="70%" OnSelectionChanged="Calendar1_SelectionChanged" OnDayRender="Calendar1_DayRender" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="top" DayStyle-Height="50px" SelectedDayStyle-BackColor="navy"></asp:Calendar>
        &nbsp;</div>
    </form>
</body>
</html>

posted by 써니루루 2007. 3. 7. 16:42

참조 : 뇌를자극하는 ASP.NET


html 테그에서 <input type=button ... > 의 형태를 asp.net에서 서버처리하는 컨트롤 입니다.
예제에서는 클라이언트 자바스크립트와 서버에서 호출되는 스크립트가 둘다 처리되는 예제를 볼 수 있습니다.

각각의 스크립트가 처리되는 시간이 어느때인지 유심히 보시면 되겠습니다.



<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> Button Control </title>
   
    <script runat="server">
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            //Response.Write("다시 게시 되었습니다.!!");
            lblText.Text = "다시 게시 되었습니다.!!";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            btnClient.Attributes.Add("onclick", "confirm('onclick')");
            btnClient.Attributes.Add("onmouseover", "document.bgColor='red';");
            btnClient.Attributes.Add("onmouseout", "document.bgColor='white';");
        }
    </script>
   
    <script type="text/javascript">
        function ConfirmPostBack()
        {
            return confirm("다시 게시하시겠습니까?");
        }
    </script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <h3>Button 예제</h3>
       
        <asp:Button ID="btnConfirm" runat="server" Text="PostBack하기" OnClientClick="return ConfirmPostBack();" OnClick="btnConfirm_Click" /><br />
        <br />
        <asp:Label ID="lblText" runat="server"></asp:Label><br />
        <br />
        <br />
        <asp:Button ID="btnClient" runat="server" Text="Button" /></div>
    </form>
</body>

</html>

posted by 써니루루 2007. 3. 7. 16:24

참조 : 뇌를 자극하는 ASP.NET p 211

HTML의 List를 출력하는 UL, LI 테그등으로 랜더링 되는 테그들입니다.
3번째 불릿티드 리스트에는 클릭이벤트의 처리를 했습니다.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="p221.aspx.cs" Inherits="p221" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>BulletedList</title>
    <script runat="server">
        protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
        {
            Response.Write("선택한 목록 번호 : " + e.Index.ToString()
                + "<br />선택한 목록 Value : "
                + BulletedList3.Items[e.Index].Value
                + "<br />선택한 목록 Text : "
                + BulletedList3.Items[e.Index].Text
            );
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 583px">
            <tr>
           
            <td>
            <h3>Disc</h3>
            <asp:BulletedList ID="BulletedList1" runat="server">
                <asp:ListItem>Item #1</asp:ListItem>
                <asp:ListItem>Item #2</asp:ListItem>
                <asp:ListItem>Item #3</asp:ListItem>
                <asp:ListItem>Item #4</asp:ListItem>
            </asp:BulletedList>
            </td>
           
            <td>
            <h3>Circle</h3>
            <asp:BulletedList ID="BulletedList2" BulletStyle="Circle" DisplayMode="HyperLink" runat="server">
                <asp:ListItem Value="http://daum.net">Item #1</asp:ListItem>
                <asp:ListItem Value="http://naver.com">Item #2</asp:ListItem>
                <asp:ListItem Value="http://yahoo.co.kr">Item #3</asp:ListItem>
                <asp:ListItem Value="http://google.co.kr">Item #4</asp:ListItem>
            </asp:BulletedList>
            </td>
           
            <td>
            <h3>Square</h3>
            <asp:BulletedList ID="BulletedList3" BulletStyle="square" DisplayMode="LinkButton" runat="server" OnClick="BulletedList3_Click">
                <asp:ListItem>Item #1</asp:ListItem>
                <asp:ListItem>Item #2</asp:ListItem>
                <asp:ListItem>Item #3</asp:ListItem>
                <asp:ListItem>Item #4</asp:ListItem>
            </asp:BulletedList>
            </td>
           
           
            <td style="width: 90px">
            <h3>Numbered</h3>
            <asp:BulletedList ID="BulletedList4" BulletStyle="Numbered" FirstBulletNumber="3" runat="server">
                <asp:ListItem>Item #1</asp:ListItem>
                <asp:ListItem>Item #2</asp:ListItem>
                <asp:ListItem>Item #3</asp:ListItem>
                <asp:ListItem>Item #4</asp:ListItem>
            </asp:BulletedList>
            </td>
           
            </tr>
           
        </table>
    </div>
    </form>
</body>
</html>

posted by 써니루루 2007. 3. 7. 11:37

출처 : 뇌를 자극하는 ASP.NET p 219


일반적으로 사이트 베너를 표시할때는 자바스크립트나 서버안에서 랜덤처리하는 부분을 구현해서 작업하게 됩니다.
이런 베너출력을 간편하게 처리할 수 있도록 제공되는 컨트롤 입니다.

예제에선 간단한 xml파일을 읽어들이도록 했지만 다른 DataSource를 바인딩할 수 있습니다.


// p219.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AdRotator</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:AdRotator ID="AdvSection1" runat="server" BorderWidth="1" BorderStyle="Dashed" Height="100px" Width="400px" AdvertisementFile="~/ad.xml" />
    </div>
    </form>
</body>

</html>



// ad.xml 파일
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
 <Ad>

  <ImageUrl>~/Images/bannger1.gif</ImageUrl>
  <NavigateUrl>http://www.microsoft.com</NavigateUrl>
  <AlternateText>마소</AlternateText>
  <Keyword>Microsoft</Keyword>
  <Impressions>50</Impressions>

 </Ad>
 <Ad>

  <ImageUrl>~/Images/bannger2.gif</ImageUrl>
  <NavigateUrl>http://www.i-ruru.com</NavigateUrl>
  <AlternateText>루루</AlternateText>
  <Keyword>ruru</Keyword>
  <Impressions>60</Impressions>

 </Ad>
 <Ad>

  <ImageUrl>~/Images/bannger3.gif</ImageUrl>
  <NavigateUrl>http://www.allblog.net</NavigateUrl>
  <AlternateText>올블로그</AlternateText>
  <Keyword>allblog</Keyword>
  <Impressions>50</Impressions>

 </Ad>
</Advertisements>