2014-08-29 1 views
2

내 asp.net 응용 프로그램에서 내 aspx 페이지에 게시물이있는 양식을 만들려고합니다.asp.net의 ASPX 페이지에서 양식 만들기

<form method="POST" action="https://www.vcs.co.za/vvonline/vcs.aspx"> 
    <input type="hidden" id="vcsTerminalId" name="p1" value="a" runat="server"/> 
    <input type="hidden" id="vcsReference" name="p2" value="b" runat="server"/> 
    <input type="hidden" id="vcsDescription" name="p3" value="c" runat="server"/> 
    <input type="hidden" id="vcsAmount" name="p4" value="d" runat="server"/> 
    <input type="hidden" id="vcsHash" name="hash" value="q" runat="server"/> 
    <input type="submit" value="Proceed to payment" /> 
</form> 

런타임 중이 양식은 사라지고 제출되지만 페이지 양식에 사용됩니다. 런타임 동안 내 전체 페이지가 양식에 배치됩니다. 나는 이것이 asp 일이라고 생각한다. 실행 시간 동안

<%@ Page Title="" Language="C#" MasterPageFile="~/template/site.master" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="mainContainer" Runat="Server"> 
//Content inside!!!!! 
</asp:Content> 

: 내 페이지에서 작업 할 때

그것은 것 같이 보입니다

<form method="post" action="SearchResult.aspx?id=1561901" id="form1"> 
//Content in side 
</form> 

는 어떻게 추가 할 수 있습니다 및 양식 언급 한 최고는?

+0

"mainContainer"에 쓸 내용은 마스터 페이지의 본문에 배치됩니다. –

+1

@ShujaatSiddiqui 그렇습니다. 내 페이지를 표시하는 곳입니다.이 페이지에는 버튼을 게시하고 싶습니다. 그래서 나는 그것을 형식으로 필요로한다. 하지만 주 컨테이너의 모든 것은 이미 양식에 배치되어 있으므로 양식을 아는 한 중첩시킬 수 없으므로 양식이 삭제되고 단지 버튼 만 있습니다. – Pomster

+0

나는 당신의 문제를 매우 간단하게하지 못하고있다. 도구 상자에서 버튼을 드래그하면됩니다. 메인 컨테이너 내부에서 버튼을 사용하여 양식을 게시 할 수 있습니다. –

답변

3

페이지 간 교차 작업을 수행하는 것은 WebForms에서는 항상 조금 어색했습니다.

해킹 깨끗 내 마크 업을 유지하기 위해, 나는 코드 숨김에서 그것을 할 수있는 헬퍼 클래스를 사용했습니다 :

RemotePost remotePostHelper = new RemotePost("https://www.vcs.co.za/vvonline/vcs.aspx"); 
remotePostHelper.Add("p1", "a"); 
remotePostHelper.Add("p2", "b"); 
remotePostHelper.Add("p3", "c"); 
remotePostHelper.Post(); 

도우미 클래스 :이 따랐다하고있다

public partial class RemotePost 
{ 
    /// <summary> 
    /// Gets or sets the remote URL to POST to. 
    /// </summary> 
    public string PostUrl 
    { get; set; } 

    /// <summary> 
    /// Gets or sets the form's HTML name. 
    /// </summary> 
    public string FormName 
    { get; set; } 

    /// <summary> 
    /// Gets the collection of POST data. 
    /// </summary> 
    public NameValueCollection PostData 
    { get; private set; } 


    /// <param name="postUrl">The remote URL to POST to.</param> 
    public RemotePost(string postUrl) 
    { 
     this.PostData = new NameValueCollection(); 
     this.PostUrl = postUrl; 
     this.FormName = "formName"; 
    } 

    /// <summary> 
    /// Adds the specified name and value to the POST data collection.. 
    /// </summary> 
    /// <param name="name">The name of the element to add</param> 
    /// <param name="value">The value of the element to add.</param> 
    public void Add(string name, string value) 
    { 
     this.PostData.Add(name, value); 
    } 

    public void Post() 
    { 
     var context = HttpContext.Current; 
     context.Response.Clear(); 
     context.Response.Write("<html><head>"); 
     context.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", this.FormName)); 
     context.Response.Write(string.Format("<form name=\"{0}\" method=\"post\" action=\"{1}\" >", this.FormName, this.PostUrl)); 

     foreach(string name in this.PostData) 
     { 
      context.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", HttpUtility.HtmlEncode(name), HttpUtility.HtmlEncode(this.PostData[name]))); 
     } 

     context.Response.Write("</form>"); 
     context.Response.Write("</body></html>"); 
     context.Response.End(); 
    } 
} 
+0

당신은 내 영웅입니다! – Pomster

+0

@Pomster 기꺼이 도와 드릴 수 있습니다 :) –

관련 문제