2012-07-30 22 views
-1

我得到了一個任務,使網頁中的「從機場」和「到機場」文本字段以及SearchFlights按鈕的內容自動驗證。點擊SearchFlights按鈕後,我得到搜索結果,我需要將這些結果與我的預期值進行比較。如何使用C#爲特定的按鈕事件調用JavaScript方法

我使用C#與HTML DOM編程設置文本字段中的文本,並點擊SearchFlights按鈕。

現在,我如何捕獲事件(例如documentcompleted)並保存這些結果以便我可以將它們與預期記錄進行比較?按鈕我有在網絡APGE看起來象下面這樣:

<a tabIndex="5" class="searchRht" id="searchBtn" onclick="sF();SearchFlights();return false;" href="" /> 

當我按一下按鈕,頁面刷新和消息出現,說:「裝載航班時刻表」,之後,它顯示結果。它看起來像onclick方法有兩個函數調用:sF()SearchFlights()

我不知道如何捕獲該網頁返回的事件和信息。

下面是用於clikcing按鈕

doc = webBrowser1.Document; 
btnElem = doc.GetElementById(streleid); 
if (btnElem != null) 
{ 
    btnElem.RaiseEvent("onclick");//click on serach button 
    btnElem.RaiseEvent("sF()"); //error comes here 
    Application.DoEvents(); // this will load the browser document again 
} 

回答

0
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultipleFunction.aspx.cs" Inherits="MultiCust_MultipleFunction" %> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 


<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Execute Multiple function with a Button</title> 
</head> 


<script language="javascript" type="text/javascript"> 
function ShowMessage() 
{ 
    alert("Hi"); 
} 


</script> 


<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> 
    </form> 
</body> 
</html> 

代碼下面是代碼後面這實現你在找什麼。

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; 

public partial class MultiCust_MultipleFunction : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     this.Button1.Attributes.Add("onClick", "ShowMessage()"); 
    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     Response.Write("Zaq"); 
    } 
} 
相關問題