Windows Develop Bookmark and Share   
 index > Windows Forms General > programmatically invoking hyperlink with webbrowser control
 

programmatically invoking hyperlink with webbrowser control

Hi,

I am viewing a webpageusing asp.net webbrowser control. there is aanchor 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 . Ihave tried the following code

:

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

and

also

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

but it doesnot work .

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

mcasangram  Wednesday, September 23, 2009 5:31 AM
Are you writing these code to documentcompleted method?
Tamer Oz  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

mcasangram  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.
Aland Li  Thursday, September 24, 2009 9:14 AM
thanks ,

but it does not work in my case .

any other suggestion .
mcasangram  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.
Aland Li  Wednesday, September 30, 2009 2:15 AM

You can use google to search for other answers

Custom Search

More Threads

• How to view data in a grid view nested within a winform
• Autocomplete TextBox for Large Datatset
• How to make datagrid components to be used in several classes.
• Rotate an Image via GDI+
• maximise mdi child form
• how can i limit the textbox to only accept numbers... and no letters
• How to hide a form and to maintain their data?
• masked textbox control
• Form's - Border Color
• How to abort SQL query execution on aborting Thread?