我有一个用户列表,在表中每一行的末尾我添加了两个链接(“href”):一个用于“更新”用户,第二个用于“删除”用户。因此,为了启用,我添加了一个对 javascript 函数的调用,该函数捕获用户的 ID 并将其插入到我之前创建的某个表单(只有一个“隐藏”字段的表单),然后该函数激活了对服务器的 submit() 操作部分(asp.net 代码)。
我检查了 submit() 操作正常(检查了 respons.write()...)
但是我知道如何通过询问提交按钮的值来识别 IsPost 中的提交表单按钮(例如: if(Request.Form["ExpertButton"]== "delete"){..some code here... .})
但是当我用 javascript 激活 submit() 时,我怎么能识别帖子?我尝试使用 hiiden 字段的值,但它没有捕捉到它,它跳过了 if 语句......
用户代码列表:
foreach(var row in db.Query(displayExperts,nameOfExpert))
{
<tr>
<td class="dispExpertActScreen">@row.ExpertID</td>
<td class="dispExpertActScreen">@row.name</td>
<td class="dispExpertActScreen">@row.password</td>
<td class="dispExpertActScreen">@row.allowBonds</td>
<td class="dispExpertActScreen">@row.allowStocks</td>
<td class="dispExpertActScreen">@row.allowExchangeTraded</td>
<td class="dispExpertActScreen">@row.allowMutualFund</td>
<td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">update</a></td>
<td class="dispExpertActScreen"><a href="#" onclick="expertToDelete('@row.ExpertID') ;return false;" style="color: #b04e4e">delete</a></td>
</tr>
}
表格代码:
<form method="post" name="deleteExpert" style="font-size: medium; margin-top: 10%" dir="rtl">
<input type="hidden" name="expertID" id="expertID" value="">
</form>
javascript代码:
<script>
function expertToDelete(expertID) {
document.getElementById('expertID').value = expertID;
document.getElementById('deleteExpert').submit ();
}
</script>
asp.net 代码:
@{
var db = Database.Open("MyProjectSite");
var display="no";
var displayExperts="";
var nameOfExpert="";
var category="";
if(IsPost)
{
if(Request.Form["ExpertButton"]== "search")// this is by button!!!
{
some code.....
}
//Response.Write("^^^^^^^^^^^^^^^^^^^^^");
if(Request.Form["ExpertButton"] != "")// this need to be by javascript submit() method !!! here I need to recognize it.
{
var id=Request.Form["expertID"];
Response.Write("^^^^^^^^^^^^^^^^^^^^^"+id);
var deleteQuery="DELETE FROM InvestmanExperts WHERE ExpertID=@0";
db.Execute(deleteQuery,id);
}
}
db.Close();
}
谢谢...