【问题标题】:Why cant I use `Invokemember("click")` to click my button programatically?为什么我不能使用 `Invokemember("click")` 以编程方式单击我的按钮?
【发布时间】:2011-05-31 13:28:47
【问题描述】:

我正在尝试通过WebBrowserControl 从我的应用程序中的网站获取数据。我可以成功登录,但是当我以编程方式调用 btnsearch.Invokemember("click") 时收到 JavaScript 错误。如果我以交互方式单击 WebBrowserControl 上的按钮,我不会收到任何错误,一切正常。

在 aspx 页面中,我有一个用于调用 Ajax 面板的 JavaScript 函数:

<script type="text/javascript">
/*<![CDATA[*/   
window["ctl00_WorkSpace_ctlCustAVIHistory_ajxResultPanel"] = new RadAjaxPanelNamespace.RadAjaxPanel({ClientID:"ctl00_WorkSpace_ctlCustAVIHistory_ajxResultPanel",EnableOutsideScripts:false,EnablePageHeadUpdate:true,Url:"/app/ModuleCustomer/ViewAVITransactions.aspx",LoadingPanelID:"ctl00_WorkSpace_ctlCustAVIHistory_LoadingPanel1",ActiveElementID:"",ClientEvents:{OnRequestStart:"",OnRequestSent:"",OnResponseReceived:"",OnResponseEnd:""},FormID:"aspnetForm",UniqueID:"ctl00$WorkSpace$ctlCustAVIHistory$ajxResultPanel"});/*]]>*/
</script>

它产生一个 UniqueID。如果我们通过代码单击btnsearch,则此唯一 ID 为空。

function onClickButton(rName) 
{
    if(validateData())
    {     
        document.getElementById("ctl00_WorkSpace_ctlCustAVIHistory_hdnReset").value = "0";    
        ctl00_WorkSpace_ctlCustAVIHistory_ajxResultPanel.AjaxRequest("NewSearch"); ///these caling down function       
    }      
}

RadAjaxPanelNamespace.RadAjaxPanel.prototype.AjaxRequest = function (eventArgument) {       
    this.AjaxRequestWithTarget(this.UniqueID, eventArgument);//this.UniqueID giving null from program click mouse click it is giving correct id 
};

知道为什么会这样吗?

【问题讨论】:

    标签: c# javascript asp.net webbrowser-control


    【解决方案1】:
        private const string STR_Field_userid = "field_userid";
        private const string STR_Field_password = "field_password";
        private const string STR_Submit = "submit";            
    
            document.GetElementById(STR_Field_userid).InnerText = UserId;
            document.GetElementById(STR_Field_password).InnerText = Password;
            document.Forms[0].InvokeMember(STR_Submit);
    

    【讨论】:

      猜你喜欢
      • 2021-04-09
      • 1970-01-01
      • 2021-07-05
      • 2013-10-09
      • 1970-01-01
      • 2017-06-17
      • 2013-05-23
      • 1970-01-01
      • 2021-09-09
      相关资源
      最近更新 更多