使用POST将数据发送到多个aspx文件

时间:2015-07-23 02:28:05

标签: c# asp.net

C# ASP.NETView.aspx一起练习写作板时。

Modify.aspx文件中,我制作了两个按钮,每个按钮都连接到Delete.aspxView.aspx。由于这两个操作都需要密码检查,(以验证编写者) 我在文本输入框中为用户输入密码,然后再单击修改或删除。

然而,问题是,如何将帖子发送到两个不同的页面。从Modify.aspxDelete.aspxPOST?由于action =方法需要View.aspx表单来指定获取数据的对象,因此我不确定如何将数据从GET发送到两个不同的页面。虽然我考虑过同时使用POSTGET,但由于内容是密码,View.aspx不合适。

以下是我的代码的一部分。 (<%@ Page Language = "C#" AutoEventWireup = "true" CodeFile = "View.aspx.cs" Inherits = "Article_view" %> <TABLE class=bg_wh cellSpacing=0 cellPadding=0 width=799 border=0> <TBODY> <TR vAlign=top> <TD height=20></TD> </TR> <TR vAlign=top> <TD align=middle> <table cellpadding="0" cellspacing="0" border="0" width="749"> <tr><td height="2" bgcolor="#CCCCCC"></td></tr> <tr bgcolor="#F2F2F2"> <td height="30" class="left pdnt_3"><b>&nbsp;Writer : <%= writer %> </b></td> </tr> <tr><td height="1" bgcolor="#DFDFDF"></td></tr> <tr> <td height="27" class="right gul f11 pdnt_3">Title : <%= title%> </td> </tr> <tr><td height="1" bgcolor="#DFDFDF"></td></tr> <tr> <td height="27" class="right gul f11 pdnt_3">Content : <%= content%> </td> </tr> <tr><td height="1" bgcolor="#DFDFDF"></td></tr> <tr> <td height="27" class="right gul f11 pdnt_3">Date : <%= writedate %> </td> </tr> <tr><td height="1" bgcolor="#DFDFDF"></td></tr> </table> <table cellpadding="0" cellspacing="0" border="0" width="749"> <tr style="padding-top:10;"> <td align="right"> <input type = "text" id = "passwordInsertion" name = write_password /> <input type="button" class="modify_button" value="modify" onclick = "window.open('Write.aspx','Write');"/> <input type="button" class="delete_button" value="delete" onclick = "window.open('Write.aspx','Write');"/> <input type="button" class="list_button" value="list" onclick = "window.open('List.aspx','_self');"/> </tr> </table> <br> </td> </tr> </table>

<script type = "text/javascript">
    function UpdateToModifyForm() {
        form_obj = document.getElementById("View_form");
        document.View_form.action = "Modify.aspx";
        form_obj.submit();
    }

    function UpdateToDeleteForm() {
        form_obj = document.getElementById("View_form");
        document.View_form.action = "Delete.aspx";
        form_obj.submit();
    }

</script>

......................

<form id = "View_form" method = "post">



<input type = "text" id = "passwordInsertion" name = write_password />
                                <input type="button" class="modify_button" value="modify" onclick = "UpdateToModifyForm();"/>
                                <input type="button" class="delete_button" value="delete" onclick = "UpdateToDeleteForm();"/>

所以我再次编辑,但它没有正确发送数据

Delete.aspx.cs

我的POST文件如下所示。 (只是为了检查密码是否通过using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class Article_Delete : CWebBase { public string password; protected void Page_Load(object sender, EventArgs e) { password = Request.Form["write_password"]; } } 发送好)

{{1}}

1 个答案:

答案 0 :(得分:1)

使用javascript,您可以执行以下操作

给你的表单一个名称属性说&#34; nameOfTheForm&#34;

function UpdateToModifyForm() {
    document.nameOfTheForm.action = "modify.aspx";
}

function UpdateToDeleteForm() {
    document.nameOfTheForm.action = "delete.aspx";
}

然后,在按钮上单击,您可以将这些功能添加到正确的按钮。