2016-08-02 3 views
1

사용자가 버튼을 클릭 할 때 HTML 파일이 VS에서 프로젝트 이름으로 동적으로 생성되고 새 탭에서 열리는 것보다 기능을 만들어야합니다.html의 새 탭에있는 버튼을 클릭하여 동적으로 html 파일을 여는 방법은 무엇입니까?

클라이언트 측에서 내 코드 : 서버 측에서 다음과 같이 내가 디렉토리 코드에서 파일을 만든

<asp:button ID="BtnGenrateHTML" runat="server" text=" Generate HTML " OnClick="btnAddnew_Click" /> 

: 보호 무효 btnAddnew_Click (개체를 보낸 사람, EventArgs입니다 E) { 문자열 sFileFullName; string sFilePath; string sFileName;

 string strHTMLGrid = ""; 
     strHTMLGrid = strHTMLGrid + "Dear Customer,<BR><BR> Please provide below OTP to complete registration <BR><BR> "; 
     strHTMLGrid = strHTMLGrid + "<BR><BR> This OTP is valid for 15 minutes."; 
     strHTMLGrid = strHTMLGrid + "<BR><BR> With Best Regards - Indiefy"; 
     This is not working //strHTMLGrid= strHTMLGrid + "<a href="abc.html/">thesitewizard.com</a>" 
     sFilePath = Server.MapPath(""); 
     sFileName = "abc.html"; 
     sFileFullName = sFilePath + "\\" + sFileName; 
     if (!Directory.Exists(sFileFullName)) 
     { 
      Directory.CreateDirectory(sFilePath); 
     } 
     // if it exist than to delete it. 
     if (System.IO.File.Exists(sFileFullName)) 
     { 
      System.IO.File.Delete(sFileFullName); 
     } 

     // If it deleted than we need to create it again 
     FileStream fs = new FileStream(sFileFullName, FileMode.Create); 
     using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) 
     { 
      w.WriteLine(strHTMLGrid); 
     } 

     fs.Close(); 
    } 

어떻게 버튼의 클릭에 내 abc.html 파일을 열지? 어떻게해야할지 안내해주세요.

은 서버 측에서 작동하지 않습니다 :

strHTMLGrid= strHTMLGrid + "<a href="abc.html/">thesitewizard.com</a>" 

답변

0

당신은 새 탭에서 링크를 엽니 다 _blank에 앵커 a 태그 태그의 target 속성을 설정할 수 있습니다. 당신은 오류가 발생할 것 따옴표 안에 큰 따옴표를 사용하는

<a href="abc.html" target="_blank"></a> 

, 당신은 아래로 백 슬래시와 따옴표를 이스케이프해야합니다.

strHTMLGrid= strHTMLGrid + "<a href=\"abc.html\" target=\"_blank\"></a>"; 

편집 버튼은 abc.html에없는 것 같습니다 당신이 당신이 아마 찾고있는 것이 아니다 abc.html 페이지가 열립니다 abc.html 앵커를 추가하려고합니다. 다른 html 파일에 버튼이 있으면 test.html을 말하고 abc.html을 열고이 버튼을 앵커로 변경하고 스타일 시트를 버튼처럼 보이게하십시오. 그런 다음 버튼을 사용하려면

<asp:button ID="BtnGenrateHTML" runat="server" text=" Generate HTML " 
    OnClick="btnAddnew_Click" OnClientClick="window.open('abc.html', '_blank'); return false;" /> 
+0

strHTMLGrid = strHTMLGrid + ""; 이것은 작동하지 않습니다 버튼을 클릭하면 Adil은 단지 새로 고칩니다. 아무것도하지 않습니다. window.open과 같은 것입니다. 여기에 글을 쓸 수 있고 url을 전달할 수 있습니다. 코드 뒤에 가능합니다. 알려주세요. 감사합니다. –

+0

업데이트 된 답변을 확인하십시오. – Adil

+1

Page.ClientScript.RegisterStartupScript (this.GetType(), "", "fncpopup();", true); 클라이언트 측에서 함수 함수를 작성한 것보다 fncpopup() { window.open ('abc.html', '_blank'); } 이것은 awsome에게 감사했습니다 –

0

난 당신이

로 변경해야한다고 생각 window.open

변경

<asp:button ID="BtnGenrateHTML" runat="server" text=" Generate HTML " OnClick="btnAddnew_Click" /> 

<a href="abc.html" target="_blank">Generate HTML</a> 

로 사용할 수 있습니다

strHTMLGrid= strHTMLGrid + "<a href='abc.html'>thesitewizard.com</a>" 
+0

Kate 답장을 보내 주셔서 감사합니다.하지만이 코드는 페이지를 새로 고칩니다. window.open에서 html 파일을 열 수있는 메소드가 있습니다. 회신을 환영합니다. –

+1

Page.ClientScript.RegisterStartupScript (this.GetType(), "", "fncpopup();", true); 클라이언트 측에서 함수 함수를 작성한 것보다 fncpopup() {window.open ('abc.html', '_blank'); } 이것은 나를 위해 일했다 awsome thanks - –