如何识别提交()从在asp.net JavaScript方法(而不是按钮)抵达 [英] how to identify submit() that arrived from javascript method(not button) in asp.net

查看:85
本文介绍了如何识别提交()从在asp.net JavaScript方法(而不是按钮)抵达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中每一行的末尾我添加了两个链接(的href)用户的列表:
一个更新的用户,并为SECEND删除的用户。
因此,对于使我加入到JavaScript函数的调用,捕捉用户的ID
并将其插入到某种形式,我之前(表格只有一个隐藏字段)创建的,
然后激活功能提交()操作的服务器部分(asp.net code)。

I have a list of users that in the end of each line in the table I added two links("href"): one for "update" user and secend for "delete" user. So for enable that I added a call to javascript function that capture the ID of user and insert it to some form that I created before (form with only one "hidden" field), and then the function activated submit() operation to the server part (asp.net code).

我检查和提交()操作工作正常(与respons.write()...选中)

I checked and the submit() operation works ok(checked with respons.write()...)

但我知道如何识别一个被提交内部IsPost表单按钮问什么价值
提交按钮(例如:如果(的Request.Form [ExpertButton] ==删除){..一些code这里....})

But I know how to recognize a submit form button inside IsPost by ask what the value of the submit button (for example: if(Request.Form["ExpertButton"]== "delete"){..some code here....})

但是,当我激活提交()使用JavaScript,我怎么可能认识张贴?
我trye​​d与hiiden字段的值,但它没有抓住这个
它skiped if语句的....

But when I activate submit() with javascript, how could I recognize post? I tryed with the value of the hiiden field but it's not capture this and it skiped of the if statement....

用户code名单:

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

形式为code:

the form code:

<form method="post" name="deleteExpert" style="font-size: medium; margin-top: 10%" dir="rtl">
    <input type="hidden" name="expertID" id="expertID" value="">
</form> 

JavaScript的code:

the javascript code:

<script>

    function expertToDelete(expertID) {

        document.getElementById('expertID').value = expertID;
        document.getElementById('deleteExpert').submit ();
    }


</script>

在asp.net code:

the asp.net code:

@{
    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();
}

感谢...

推荐答案

为什么不思想促进另一个隐藏的输入值:

Why not puting another hidden input value :

<input type="hidden" name="txtJavascriptMode" id="txtJavascriptMode" value="">

然后在你的JavaScript code:

then in your javascript code :

<script>
    function expertToDelete(expertID) {

        document.getElementById('expertID').value = expertID;
        document.getElementById('txtJavascriptMode').value = 'true';
        document.getElementById('deleteExpert').submit ();
    }
</script>

和在你的服务器端,你可以检出

and in your serverside you can checkout

if(Request["txtJavascriptMode"] == "true")
{}

这篇关于如何识别提交()从在asp.net JavaScript方法(而不是按钮)抵达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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