为什么我不能使用`Invokemember(“click”)`以编程方式单击我的按钮?

时间:2011-05-31 13:28:47

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

我正在尝试通过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为null。

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

知道为什么会这样吗?

1 个答案:

答案 0 :(得分: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);