none
programmatically invoking hyperlink with webbrowser control

    Question

  •  Hi,

    I am viewing a webpage using asp.net  webbrowser control . there is a anchor element in a grid rendering following html code  :

    <A-align:center; id=ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_btnInsert style="FONT-SIZE: 12px"
    href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$gvContractDetails$ctl03$btnInsert", "", true, "EmployeeContractSummary", "", false, true))'>Save</A>

    I want to programmaticaly invoke click event of the hyperlink . I have tried  the following code

    WebBrowser1.Document.All("ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_btnInsert").InvokeMember("Click")

    and

    also

     

    WebBrowser1.Document.Links(15).RaiseEvent("Click")

     

    but it does not work .

    Anybody kindly can help me in this regard . it's very urgent

    Wednesday, September 23, 2009 5:31 AM

All replies

  • Are you writing these code to documentcompleted method?
    Wednesday, September 23, 2009 5:51 AM
  • no ,

    as i think webbrowser documentcompleted method is invoked when a button with post back is called using InvokeMember

    Method of webbrowser . But in my case the Hyperlink(ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_btnInsert) i have described above loads on a Button(ctl00_ContentPlaceHolder1_BtnNew)   click  without postback

    (probably using ajax) . the hyperlink is present inside a gridview . 

    i am using the following code :


    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtLastName").SetAttribute("Value", "sa")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtFirstName").SetAttribute("Value", "sa")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtSSN").SetAttribute("Value", "098765431")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtDOB").SetAttribute("Value", Format(CDate("09/09/1981"), "MM/dd/yyyy").Trim())

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_ddlCurrentDOEEmployee").SetAttribute("Value", "N")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtAddress1").SetAttribute("Value", "ny 1345")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtCity").SetAttribute("Value", "Ca")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_ddlState").SetAttribute("Value", "OH")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtZipCode").SetAttribute("Value", "12345")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_TxtPrimaryPhoneNum").SetAttribute("Value", "6565654663")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_BtnNew").InvokeMember("Click")

    System.Threading.Thread.Sleep(10000)

     

    Dim pvoEle As System.Windows.Forms.HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("table")

     

    Dim pviCount As Integer

     

    For pviCount = 0 To pvoEle.Count

     

    If pvoEle.Item(pviCount).Id <> "" Then

    MessageBox.Show(pvoEle.Item(pviCount).InnerHtml)

     

    End If

     

    Next

     

    WebBrowser1.Document.All("ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_ddlContract_New").SetAttribute("Value", "311")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_ddlContract_New").RaiseEvent("onChange")

    System.Threading.Thread.Sleep(10000)

     

    For pviCount = 0 To pvoEle.Count - 1

     

    If pvoEle.Item(pviCount).Id <> "" Then

    MessageBox.Show(pvoEle.Item(pviCount).InnerHtml)

     

    End If

     

    Next

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_ddlWorkSite_New").SetAttribute("Value", "PETSND1***311")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_ddlWorkTitle_New").SetAttribute("Value", "5540")

    WebBrowser1.Document.All(

    "ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_ddlRosterStatus_New").SetAttribute("Value", "A")

    WebBrowser1.Document.All("ctl00_ContentPlaceHolder1_gvContractDetails_ctl03_btnInsert").InvokeMember("Click")

     


    System.Threading.Thread.Sleep(20000)


    Thanks

     

     

    Wednesday, September 23, 2009 11:11 AM
  • Hi mcasangram,

    Please take a look at this thread:
    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/b2f06f3e-a513-47e0-bd13-892636436ad3/

    Regards,
    Aland Li

    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, September 24, 2009 9:14 AM
    Moderator
  • thanks ,

    but it does not work in my case .

    any other suggestion .
    Tuesday, September 29, 2009 6:46 AM
  • Hi mcasangram,

    Could you let us know why it does not work in your case?

    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Wednesday, September 30, 2009 2:15 AM
    Moderator
  • Did you get an answer or solve this.  I have the same problem.
    Saturday, October 08, 2011 3:28 AM