如何在代码隐藏而不是html标记中执行此任务? [英] how to do this task in code-behind instead of html markup?

查看:93
本文介绍了如何在代码隐藏而不是html标记中执行此任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html标记中使用以下代码将数据提交到网关,然后将其重定向到网关网址。

 <  表格   操作  =  <% = Settings.FormPaymentUrl%>   方法  =  post    id   =  PayForm  
名称 = PayForm >
< 输入 类型 = 隐藏 名称 = VPSProtocol value = <% = Settings.ProtocolVersion.VersionString()%> / >

< 输入 类型 = 隐藏 名称 = TxType value = <% = Settings.DefaultTransactionType %> / >
< 输入 type = hidden < span class =code-attribute>
name = 供应商 value = <% = System.Configuration.ConfigurationManager.AppSettings [ getvendorname]%> / >
< 输入 类型 = hidden name = 地穴 value = < % =加密%> / >
< 输入 类型 = image 名称 = cmdProceed src = images / proceed.png alt = 继续进行表单注册 / >

< / form < span class =code-keyword>>





但现在我想做同样的任务从代码隐藏而不是HTML标记。我想从代码隐藏后发布四个输入隐藏字段,之后它应该被重定向到网址。我已经尝试了很多东西,但都是徒劳的..希望你的家伙会帮助我..

解决方案

你不能从服务器端做到这一点。如果你想在进入支付平台之前运行一些代码服务器端,那么你可以向你的页面提交一个表单,该页面可以执行代码,然后输出一个与上面相同的表格的空白页面,只有你可以自动 - 通过javascript(谷歌自动提交表格javascript,如果你不知道如何)提交它,所以用户没有真正看到任何东西,它去了支付平台。


严格说来,这个问题毫无意义,因为你的HTML什么都不做,它不会向服务器提交任何内容,因为缺少提交按钮;它应该是< input> 元素,类型=提交。



但是如果我可以假设你拥有一切,你的表格将使用post方法提交一些数据。 HTTP请求将包含键值对中的所有表单元素的数据,其中键等于 name 属性的对应值。



要在后面的ASP.NET代码中执行相同的操作,可以使用类 System.Net.HttpWebRequest

https://msdn.microsoft.com/en- us / library / system.net.httpwebrequest%28v = vs.110%29.aspx



-SA

i am using the following code in my html markup to submit data to the gateway and after that it is redirected to the gateway url.

<form action="<%= Settings.FormPaymentUrl %>" method="post" id="PayForm"
                           name="PayForm">
                           <input type="hidden" name="VPSProtocol" value="<%= Settings.ProtocolVersion.VersionString() %>" />

                           <input type="hidden" name="TxType" value="<%= Settings.DefaultTransactionType %>" />
                           <input type="hidden" name="Vendor" value="<%= System.Configuration.ConfigurationManager.AppSettings["getvendorname"] %>" />
                           <input type="hidden" name="Crypt" value="<%= Crypt %>" />
                         <input type="image" name="cmdProceed" src="images/proceed.png" alt="Proceed to Form registration" />

                           </form>



But now i want to do same task from the code-behind instead of html markup. i want to post four input hidden fields from code-behind after that it should be redirected to the url. i have tried many things but all in vain.. hope you guyz will help me..

解决方案

You can't do this from the server-side. If you want to run some code server-side before going to the payment platform then you can submit a form to your page, that page can do the code then output a blank page with the same form you have above, only you can auto-submit it via javascript (google "auto submit form javascript" if you don't know how) so the user doesn't really see anything, it goes goes to the payment platform.


Strictly speaking, the question makes no sense, because your HTML does nothing, it does not submit anything to the server, because the "Submit" button is missing; it should be <input> element with the type="submit".

But if I could assume you have it all, your form would submit some data using the method "post". The HTTP request would contain all the form elements' data in key-value pairs, with keys equal to corresponding values of name attributes.

To do the same thing in ASP.NET code behind, you could use the class System.Net.HttpWebRequest:
https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx.

—SA


这篇关于如何在代码隐藏而不是html标记中执行此任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆