簡體   English   中英

如何在ascx控件的asp.net中添加表單和類標記

[英]How to add form and class tag in asp.net in ascx control

這是我的控制

<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>

這是我的js函數,旨在用於創建html表單。

function submitResponsePaymega(dPayment, dSignature, dId, loc, cProduct, url) {

    var payment = $get('payment_method');
    payment.value = dPayment;

    var key = $get('data-key');
    key.value = dKey;

    var signature = $get('signature');
    signature.value = dSignature;

    var id = $get('uniqueuserid');
    id.value = dId;

    var product = $get('customproduct');
    product.value = cProduct;

    var locale = $get('locale');
    locale.value = loc;

    submitForm(url);
}

這是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();
}

我如何獲得帶有類屬性的這種生成形式的結果?

<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代碼添加到頁面中以提交邏輯。

請注意,這只是代碼示例,顯示了我們如何實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM