Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在ascx控件的asp.net中添加窗体和类标记_Javascript_C#_Asp.net_.net_Webforms - Fatal编程技术网

Javascript 如何在ascx控件的asp.net中添加窗体和类标记

Javascript 如何在ascx控件的asp.net中添加窗体和类标记,javascript,c#,asp.net,.net,webforms,Javascript,C#,Asp.net,.net,Webforms,这是我的控制 <asp:Panel runat="server"> <input type="hidden" id="signature" name="signature" value="" /> <input type="hidden" id="uniqueuserid" name="uniqueuserid" value="" /> <input type="hidden" id="locale" name="loca

这是我的控制

<asp:Panel runat="server">    
    <input type="hidden" id="signature" name="signature" value="" />
    <input type="hidden" id="uniqueuserid" name="uniqueuserid" value="" />
    <input type="hidden" id="locale" name="locale" value="" />
    <input type="hidden" id="customproduct" name="customproduct" value="" />
</asp:Panel>
这里是submitform函数

function submitForm(url) {

    var frm = document.forms[0];

    var vs = $('#__VIEWSTATE');
    if (vs) {
        vs.remove();
    }

    var ev = $('#__EVENTVALIDATION');
    if (ev) {
        ev.remove();
    }

    var et = $('#__EVENTTARGET');
    if (et) {
        et.remove();
    }

    var ea = $('#__EVENTARGUMENT');
    if (ea) {
        ea.remove();
    }

    var vg = $('#__VIEWSTATEGENERATOR');
    if (vg) {
        vg.remove();
    }

    frm.action = url;
    frm.submit();
}
我如何使用atribute类实现这种生成形式的结果

<form method="post" action="https://pp.pay.com/">
    <input type="hidden" name="key" value="key">
    <input type="hidden" name="customproduct" value="[{'Id':'1','type':'fixedProduct','name':'Product name','currency':'RUB','amount':100}]">
    <input type="hidden" name="signature" value="signature">
    <button type='submit'>Pay</button>
</form>

支付

请注意,我对从mvc迁移的WEB表单是完全陌生的。要获得表单标签,我们应该创建页面/WEB表单。 在页面中注册控件并使用它。这样我们就可以实现您真正需要的

请查找下面的代码。我希望这是你所期待的

用户控制代码

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication2.WebUserControl1" %>
<asp:Panel runat="server" ID="UserControl">    
    <input type="hidden" id="signature" name="signature" value="" />
    <input type="hidden" id="uniqueuserid" name="uniqueuserid" value="" />
    <input type="hidden" id="locale" name="locale" value="" />
    <input type="hidden" id="customproduct" name="customproduct" value="" />
</asp:Panel>

网页表单代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register TagPrefix="tc" TagName="TestControl" Src="~/WebUserControl1.ascx"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head> 
<body>
    <form id="form1" runat="server">
        <tc:TestControl runat="server"></tc:TestControl>
        <input type="hidden" name="key" value="key"/>
        <input type="hidden" name="customproduct" value="[{'Id':'1','type':'fixedProduct','name':'Product name','currency':'RUB','amount':100}]"/>
        <input type="hidden" name="signature" value="signature"/>
        <button type='submit'>Pay</button>
    </form>
</body>
</html>

支付
您可以将javascript代码添加到页面以进行提交逻辑

请注意,这只是一个代码示例,以展示我们如何实现

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register TagPrefix="tc" TagName="TestControl" Src="~/WebUserControl1.ascx"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head> 
<body>
    <form id="form1" runat="server">
        <tc:TestControl runat="server"></tc:TestControl>
        <input type="hidden" name="key" value="key"/>
        <input type="hidden" name="customproduct" value="[{'Id':'1','type':'fixedProduct','name':'Product name','currency':'RUB','amount':100}]"/>
        <input type="hidden" name="signature" value="signature"/>
        <button type='submit'>Pay</button>
    </form>
</body>
</html>