2011-05-16 16 views
1

我在VB ASP.NET页面用下面的代码(这是由VS生成):动态地从一个字符串注入HTML代码到一个asp.net页

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Payment2.aspx.vb" Inherits="Payment2" %> 

<!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></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 

    </div> 
    </form> 
</body> 
</html> 

随着代码

Partial Class Payment2 
    Inherits System.Web.UI.Page 

    Sub Page_Load(ByVal S As Object, ByVal E As EventArgs) 

    End Sub 

End Class 

我希望能够将下列字符串注入页面并显示。

<form name="downloadform3D" action="https://something.asp" method="post"> 
<NOSCRIPT> 
JavaScript is currently disabled or is not supported by your browser.<br> 
Please click on the &quot;Continue&quot; button to continue<br> 
<input class="ncol" type="submit" value="Continue" id="submit1" name="submit1" /> 
</NOSCRIPT> 
<input type="hidden" name="CSRFKEY" value="abc" /> 
<input type="hidden" name="CSRFTS" value="abc" /> 
<input type="hidden" name="CSRFSP" value="/ncol/test/something.asp" /> 
<input type="hidden" name="PaReq" value="<?xml version=&quot;1.0&quot;?><ThreeDSecure><Message id=&quot;123&quot;><PAReq><version>1.02</version><Merchant><merID>abc</merID><name>abc</name><url>http://www.abc.com</url></Merchant><Purchase><xid>123</xid><amount>1</amount><purchAmount>1</purchAmount><currency>GBP</currency></Purchase><CH><acctID>12345</acctID><expiry>1234</expiry><selBrand></selBrand></CH></PAReq></Message></ThreeDSecure> 
" /> 
<input type="hidden" name="TermUrl" value="https://something.asp" /> 
<input type="hidden" name="MD" value="12334" /> 
</form> 
<form method="post" action="https://somethig.asp" name="uploadForm3D"> 
<input type="hidden" name="CSRFKEY" value="1234A" /> 
<input type="hidden" name="CSRFTS" value="1234" /> 
<input type="hidden" name="CSRFSP" value="/something.asp" /> 
<input type="hidden" name="branding" value="abc" /> 
</form> 
<SCRIPT LANGUAGE="Javascript" > 
<!-- 
var popupWin; 
var submitpopupWin = 0; 

function LoadPopup() { 
if (self.name == null) { 
    self.name = "ogoneMain"; 
} 
popupWin = window.open('about:blank', 'popupWin', 'height=400, width=390, status=yes, dependent=no, scrollbars=yes, resizable=no'); 
if (popupWin != null) { 
    if (!popupWin || popupWin.closed) { 
     return 1; 
    } else { 
     if (!popupWin.opener || popupWin.opener == null) { 
      popupWin.opener = self; 
     } 
     self.document.forms.downloadform3D.target = 'popupWin'; 
     if (submitpopupWin == 1) { 
      self.document.forms.downloadform3D.submit(); 
     } 
     popupWin.focus(); 
     return 0; 
    } 
} else { 
    return 1; 
} 
} 
self.document.forms.downloadform3D.submit(); 
//--> 
</SCRIPT> 

我已经看过谷歌,但没有任何帮助(我可能会输入错误的搜索条件,因为我是网络编程的新手)。任何帮助将是非常赞赏,因为我不是一个ASP的家伙,我已经拉了什么小头发,我现在已经离开了3天:(

在此先感谢。

回答

1

你可以做的Response.Write,

你可以用asp:文字

有几种模式与asp:文字控制

PassThrough呈现内容“原样”,包括HTML标记和脚本。如果你不完全控制输出,这是一个坏主意。如果您动态地包含任何可能来自用户输入或存储在数据库中的值的任何内容,则可能会使自己处于安全风险之中。

编码是HTML编码的。它的对待像文本不是HTML所以这不会为你工作

变换试图改变标记来匹配浏览器可能或可能无法正常工作。

另一种选择是使用用户控件并根据需要设置其“可见”属性。

+0

感谢您的支持。完全按照我希望的方式使用Response.Write 也要感谢@Anuraj – robert 2011-05-16 09:53:42

0

你有没有尝试过回应。 。写(内容);在Page_Load事件如果内容是数据要注入到页面

2

从你的问题似乎你试图从服务器端插入字符串,但我认为它最好在aspx页面本身。

从aspx页面中删除此代码:

<form id="form1" runat="server"> 
    <div> 

    </div> 
    </form> 

,并把你的代码来代替。它应该看起来像这样:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Payment2.aspx.vb" Inherits="Payment2" %> 

<!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></title> 
</head> 
<body> 
<form name="downloadform3D" action="https://something.asp" method="post"> 
<NOSCRIPT> 
JavaScript is currently disabled or is not supported by your browser.<br> 
Please click on the &quot;Continue&quot; button to continue<br> 
<input class="ncol" type="submit" value="Continue" id="submit1" name="submit1" /> 
</NOSCRIPT> 
<input type="hidden" name="CSRFKEY" value="abc" /> 
<input type="hidden" name="CSRFTS" value="abc" /> 
<input type="hidden" name="CSRFSP" value="/ncol/test/something.asp" /> 
<input type="hidden" name="PaReq" value="<?xml version=&quot;1.0&quot;?><ThreeDSecure><Message id=&quot;123&quot;><PAReq><version>1.02</version><Merchant><merID>abc</merID><name>abc</name><url>http://www.abc.com</url></Merchant><Purchase><xid>123</xid><amount>1</amount><purchAmount>1</purchAmount><currency>GBP</currency></Purchase><CH><acctID>12345</acctID><expiry>1234</expiry><selBrand></selBrand></CH></PAReq></Message></ThreeDSecure> 
" /> 
<input type="hidden" name="TermUrl" value="https://something.asp" /> 
<input type="hidden" name="MD" value="12334" /> 
</form> 
<form method="post" action="https://somethig.asp" name="uploadForm3D"> 
<input type="hidden" name="CSRFKEY" value="1234A" /> 
<input type="hidden" name="CSRFTS" value="1234" /> 
<input type="hidden" name="CSRFSP" value="/something.asp" /> 
<input type="hidden" name="branding" value="abc" /> 
</form> 
<SCRIPT LANGUAGE="Javascript" > 
<!-- 
var popupWin; 
var submitpopupWin = 0; 

function LoadPopup() { 
if (self.name == null) { 
    self.name = "ogoneMain"; 
} 
popupWin = window.open('about:blank', 'popupWin', 'height=400, width=390, status=yes, dependent=no, scrollbars=yes, resizable=no'); 
if (popupWin != null) { 
    if (!popupWin || popupWin.closed) { 
     return 1; 
    } else { 
     if (!popupWin.opener || popupWin.opener == null) { 
      popupWin.opener = self; 
     } 
     self.document.forms.downloadform3D.target = 'popupWin'; 
     if (submitpopupWin == 1) { 
      self.document.forms.downloadform3D.submit(); 
     } 
     popupWin.focus(); 
     return 0; 
    } 
} else { 
    return 1; 
} 
} 
self.document.forms.downloadform3D.submit(); 
//--> 
</SCRIPT> 
</body> 
</html> 
相关问题