By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,588 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,588 IT Pros & Developers. It's quick & easy.

Firing Click events and Reading IFrame Source of External URL in ASP.NET web form

P: n/a
Hi

I have developed a Windows Application(C# Windows Form) which will get the IFrame Source of the page it is navigating using Webbrowser Control. Now I want do this in ASP.Net web application(C# Web Form).

Is there any other method through which I will be able to access the IFrame Source of the page I am navigating to. Also I need to click on some of the links in the page I am navigating. Requirement is to read the data the IFrame source is contains.

I tried using Webbrowser Control in ASP.Net Web Form but once the Webbrowser Control is placed on Web Form, if the application is run, getting Page cannot be displayed error. Also tried calling Windows Application (.exe) which is already developed in ASP.Net web form, that is also not working

Please anybody can help me how to read the IFrame Source and Fire Click events of page it is navigating through in ASP.Net. From our portal we need to navigate to external URL. Once it is navigated to externalURL, I have to fire some click events and read the IFrame source.

Regards
E
Nov 18 '05 #1
Share this Question
Share on Google+
24 Replies


P: n/a
HI Ej,

From your description, you used to use WebBrowser Control in your winform
app and navigate some pages from external sites and do some operations on
the retrieved page's dom collection, also programmatically fire some events
on those page. And now you'd like to move such function in an asp.net web
page. You use the iframe element to contain the external page and wonder
how to control the page in the iframe , yes?

As for this problem, here are my suggestions:
1. In web page, we generally can use javascript to manipulate the iframe
element embeded in a certain web page. For example, change its url , get
its frame or docuemnt object and loop through its html elements collecton.
However, this has the limitation that we can only do such operations on a
page which is from the same domain of the container page(where the iframe
is in ). For example our web app's in the www.mydomain.com and one page
contains the iframe. if the iframe's containing page is also from the same
domain , such as a.mydomain.com or b.mydomain.com, it'll be ok for us to
use javascript to requry the dom collection of the iframe page, otherwise,
we'll be unable to do so(will encounter permission denied error). Here are
some related tech articles:

http://www.codeproject.com/jscript/slite.asp

http://www.oreillynet.com/pub/a/java...08/iframe.html

2. If you do want to implement the same functions as your winform app, I
think you can create a Winform control which wrapper the WebBrowser control
and also encapsualte all those functions(such as get the navigated page's
source and fire some events on it). And then, embeded the winform control
in your web page. This is called IE hosted winform control. But that'll
need the clientside to grant enought permissions to run the rich client
control in IE. Below are some referene on IE host winform control:

http://samples.gotdotnet.com/quickst...eSourcing.aspx

#Simple way to expose a .NET WinForm control as an ActiveX control in any
HTML page
http://www.codeproject.com/cs/miscct...wincontrol.asp

Hope helps. Thanks..

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx




Nov 18 '05 #2

P: n/a
Yes, your undestanding of question is right.

I tried the sample from codeproject and it works only if the usercontrol file is placed within the application folder, if it is placed in bin folder, on click of Button, undefined message is displayed

Now I tried placing Webbrowser Control similar way onto the Webform, but nothing is happening. No mesage os also getting displayed. What can be the reason

Is there any other approach is there to read the external URL source through ASP.Net Webfrom

Thanks
EJ
Nov 18 '05 #3

P: n/a
HI Steven

When a usercontrol is created placing a AxWebbrowser Control in it and placed this usercontrol inside webform and executed the control itself is not getting displayed. If any other controls are placed in user control and tried there is no problem everything works fine.

What is the solution for this? Or Is there any other way to read source code of external URL we are navigating to

Please help us.

Thanks
Vani
Nov 18 '05 #4

P: n/a
HI All

Please anybody give us the solution. There are no replies coming for this question. Time is running out, please help us

Thanks
EJ
Nov 18 '05 #5

P: n/a
Hi Vani

I'm sorry to hear that the Embeded WebBrowser in a asp.net UserControl
bings new troubles. In fact I also suspect whether this is an appropriate
approach. Since you mentiond that get the response's html source of the
remote url. The "HttpWebRequest" class come to my mind, it can help post
request to a certain web url address and retrieve back the httpResponse
from it. The response is returned as an HttpWebResponse class's instance
and we can get the response html source from the Stream it contained. But
if you want to manipulcate the source as a DOM collection, we still need to
manually parse it. Here are some certain web resources on using the
HttpWebRequest:

#HttpWebRequest.GetResponse Method
http://msdn.microsoft.com/library/en...NetHttpWebRequ
estClassGetResponseTopic.asp?frame=true

#How to use HttpWebRequest to send POST request to another web server
http://www.netomatix.com/HttpPostData.aspx

#Crawl Web Sites and Catalog Info to Any Data Store with ADO.NET and Visual
Basic .NET
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
http://blogs.toneengel.com/btone/arc...09/22/192.aspx

Hope helps. Also, please feel free to post here if there are anything else
we can help. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6

P: n/a
Thanks for the reply.

We can not use webrequest and webresponse since we need to show the Remote URL to Users and they need to login to the Remote URL. Once they login to remote URL our application has to do click on some links before reading required data from the Iframe Source.

So is there any other way out to do this? please help us...,

Thanks,
EJ
Nov 18 '05 #7

P: n/a
HI Steven

Thanks for in depth research. We will try the same and get back to you

I am unable to see the attached code of the test Winform Control which you have tried. Can you repost the same

Thanks
EJ
Nov 18 '05 #8

P: n/a
Hi EJ,

The attachment in the thread is visible when you are using the OE the view
the thread, if you are visiting the thread via
web client, I'm afraid you can't see the attachment. So please make sure
you're using OE client. Also, if you feel convenient, you can provide the
mail address so that I can attach it via mail. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #9

P: n/a
HI Steven

You can send the sample code to above ID

Also the sample code for using it ASP.Net webform

Thanks
E
Nov 18 '05 #10

P: n/a
HI Steven

Still I have not received the reply from you. I am waiting to get the attachment via mail. Please send the code as attachment to the above mail id

Thanks
EJ
Nov 18 '05 #11

P: n/a
Hi EJ,

I've just send the attachment(the webbrowser's wrapper winform control's
project) via the
va***********@megasoft.com
Address, please let me know if you've got it.
You can rebuild it on your side before using it. As for the page to use
it, it's very simple , just add the following tag in page source:

<object width="100%" height="100%" id="MyWBMain"
classid="http://webservername/webapplicationname/WBLib.dll#WBLib.MyBrowser"
VIEWASTEXT></object>

Note that I put the WBLib.dll and all its dependence ( the interop com
wrapper for the webbrowser control) in the same folder with the page using
it.

And as I've mentioned, your problem is probably caused by security issue on
the client machine. Because by default the embedded webbrowser control will
not be allowed to execute in clientmachine's IE hosted CLR enviroment. You
need to add a codegroup for the certain assembly(using the .net
configuration tool in the Administrator tools ), you can add an codegroup
under the LocalIntranet_Zone and specify its evendence with Url and specify
the url with the certain assembly's path such as
http://webservername/webapplicationname/WBLib.dll
or you can even specify the upper level path such as
http://webservername/webapplicationname/*

and grant FullTrust with this codegroup. Thus, the assembly from this url
will have FullTrust permission to run in the client's IE host CLR
enviroment. Also, I've attached some screenshots in the mail. If you have
any questions, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #12

P: n/a
HI Steven

Thanks, I received the mail which u sent.

I followed the steps which u listed out, but still all other WIndows User controls works fine, except the Windows User Control which contains Webbrowser Control.

No error also coming, what can be done?

What can be the problem? What is the solution for this?

Please let me know, really we are stuck, early response will help us

Thanks
EJ
Nov 18 '05 #13

P: n/a
Hi EJ,

Thanks for your followup. I still think the problem we meet now is due to
security setting. I'd like to correct one thing I mentioned in the last
reply.

I mentioned that you can create the codegroup and specify the Url evidence
as
=======================
the url with the certain assembly's path such as
http://webservername/webapplicationname/WBLib.dll
or you can even specify the upper level path such as
http://webservername/webapplicationname/*
=======================

I've tested and found that they not worked and we have to specify the url
from the website's sitename such as

Http://webservername/*

Please try changing the codegroup's url to this style to see whether it
helps.

Also, one more simple way to confirm the security issue is adjusting the
LocalIntranet_Zone's Permission set,
change the "LocalIntranet_Zone"'s trust level to "FullTrust" , and then
test again to see whether it works. I've also attached the screen shot for
this means via email, please also check it.
#notice that when we do some modification on security changes or in page
which embeded the wniform control, we need to close the IE and restart a
new one to test again.

Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #14

P: n/a
HI Steven

Thanks for the response. But I have not rcvd any images with the email

I have sent the Webapplication where I am using the User control containin
webbrowser Control(which u had sent) . So U can also test it in ur system
If anything else other than security problem, let me know

I have given permission to IP address of the system(eg: http://x.x.x.x
under codegrup in LocalIntranet_Zone. In the ClassId property also, i hav
given http://x.x.x.x as path for DLL

Let me know, how to solve this problem

Thanks
Van

Nov 18 '05 #15

P: n/a
Hi Vani,

I've receieved the project. I would have a try as soon as possible. Also,
during the time, you can also try
changing the LocalIntranet_Zone's trust level your side to see whether it
helps. I'll update you as soon as I've got some new updates. Good luck.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #16

P: n/a
HI Steven

Thanks

I have given FULL Trust in both Internet Settings(for Trusted Site) and as well as under Codegroup

But still it does not seem to work. I tried to debug, but it does not go inside the User Control Code at all

What is ur system Configuration? I am testing it on Windows 2000 with IE 6 with latest patches.

Still I have not received the Screen Shots which u had sent in the previous mail

Hope this problem will be solved atleast by today

Thanks
Van

Nov 18 '05 #17

P: n/a
Hi EJ,

I've tested the WebApplication you sent me. I attached it on a W2k
server(SP4) machine and create Virtual DIR to host it, and viewing the page
which contains the Winform control. I haven't encountered any problems. It
worked fine.
Currently I haven't any definite ideas, I've resent the mail(contains
screen shot on adjust the client machine's LocalIntranet_Zone" 's trust
level in .net configuration tool.
#notice that if you have installed both .net 1.0 and 1.1 framework on the
machine. Make sure that you are using the .net configuration tool 1.1
rather than the old one.

And here is a kb article on how to debug IEHost Object issues
#HOW TO: Use the IEHost Log to Debug .NET Object Hosting in Internet
Explorer
http://support.microsoft.com/?id=313892

I think you may make use of the log mentioned in it to trace the acutal
error at client machine.

Also, I've found that you've posted another new thread titled
"Subject: ThreadStateException problem"
in the group. I'll also posted my reply there. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #18

P: n/a
HI Steven

Are you using Windows Server 2000. I am using system with Win 2000 Professional with SP4. Is this is the problem?

For me the page is not displaying the user control on the same system where it is developed and hosted as well.

Anyway i will use the IEHost Dll to debug the application and let you know

What else could be the problem? Why it is showing up the controkl in our system

Thanks
E
Nov 18 '05 #19

P: n/a
Hi EJ,

I've replied in the
"ThreadStateException problem" Issue,
If you have any new findings, please feel free to post in either one.
Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #20

P: n/a
HI Steven

Sorry for getting back late. Thanks a lot Steven. Finally it is working fine after setting the Full Trust under Adjust Security Policy. Once again Thanks a lot for your patience and continuous supprt

Now it is working fine. But I have some more queries on the same

1. We are opening the webform containg Webbrowser Control in a popup window. On click of a button in the User control I am opening the external URL. Now our external URL needs User name and password inputs to login to their system. I am using Navigate2 method of axwebbrowser control, which returns void. I want to check whether the navigation to the external URL is successfull or not. How can do this check

2. Inside the UserControl I am saving some data to a file. Now I want to give the path where I want to save that file. I don't want to hard code the path inside the User Control. Also since this user control runs on client's system, I want to save the file on the server where the application is running, not on the client's system. So I want to pass the server Folder Path where I want to save this file. Also I need to connect to the Database on the application server from the user control, How can I do this

3. I want to close some of the objects on unload of this user control, how can I do this, Can I do it on Dispose

If you want to create this in a different thread let me know.

Thanks
Vani
Nov 18 '05 #21

P: n/a
Hi EJ,

If you have any new findings or need any futher help, please feel free to
post here or in another
"ThreadState EXception" Thread. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #22

P: n/a
Hi Ej,

Thanks for the response. It seems that you've got the winform control
displaying in web page, yes?

To answer your question in last reply here:

1. We are opening the webform containg Webbrowser Control in a popup
window. On click of a button in the User control I am opening the external
URL. Now our external URL needs User name and password inputs to login to
their system. I am using Navigate2 method of axwebbrowser control, which
returns void. I want to check whether the navigation to the external URL is
successfull or not. How can do this check?
================================================== ==============
If you want to capture the state when the navigate or navigate2 method is
completed, there are two useful events
NavigateComplete
NavigateComplete2
We can add handler for either of them so as to do some operations when the
navigation to a certain webresource or document is completed. Here are some
useful weblinks:

HOWTO: Use the WebBrowser Control to Open Office Documents with Visual C#
..NET
http://support.microsoft.com/?id=304662

#Using the WebBrowser control, simplified.
http://www.codeproject.com/miscctrl/...wserformfc.asp

2. Inside the UserControl I am saving some data to a file. Now I want to
give the path where I want to save that file. I don't want to hard code
the path inside the User Control. Also since this user control runs on
client's system, I want to save the file on the server where the
application is running, not on the client's system. So I want to pass the
server Folder Path where I want to save this file. Also I need to connect
to the Database on the application server from the user control, How can I
do this?
================================================== =================
Since the Winform UserControl is running in the clientside, so we're not
able to generate the serverside path in winform control's code. MY
suggestion is we use the <object ... > 's <param> tag to set the paramter
for the control via asp.net code, for example
<object ...>
<PARAM NAME="BasePath" VALUE='<%= Server.MapPath("~/pic") %>'>
</object>
3. I want to close some of the objects on unload of this user control, how
can I do this, Can I do it on Dispose?
================================================== =====================
Since the IE host winform/activex controls are in IE host enviroment, IE
will control their life cycle. and Generally when a certain browser's
instance ended, the in memory resources will be released. And as for the
winform control, you can make use of its dispose interface to release some
objects.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #23

P: n/a
Hi EJ,

Thanks for the followup. I've read the code you provided and also perform
some tests on my side regarding on the question in your last reply. Here is
my suggestion:

Since the WebBrowser control's Document_Complete event is async , I think
we'd better not use foreach or for (...) to
loop through the collections. My solution is
1.when the Main page is completed download or rendered and then loopthrough
all those links and put them in a Array( a class member of the winform
control class so that we can retrieve it in all the functions). Also, put
another int member to store the current_index in the array. Call the
Array[0].click() and set the current_index = 0

2. Then in the DocumentComplete event, if it is the iframe docuemtn be
completely loaded, check the current_index,
if not end of the Array, then increase it by 1 and call the click method of
the current_index item. such as
if(current_index < templinks.Length-1)
{
current_index++;
Array[current_index].click();
}
So the complete DocumentComplete event is like below:

#templinks is the Array of the certain HTMLElement class member
#current_index is the member store the current html element's index

private void axWB_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
string url = (string)e.uRL;
if(url.IndexOf("ListFrame.aspx") != -1)
{

IHTMLDocument2 HTMLDocument = (IHTMLDocument2) axWB.Document;
IHTMLElementCollection links = HTMLDocument.links;

templinks = new HTMLAnchorElementClass[links.length];
int i = 0;
foreach (HTMLAnchorElementClass el in links)
{
templinks[i] = el;
i++;
}

current_index = 0;
templinks[current_index].click();
}
else if(url.IndexOf("IFramePage.aspx") != -1)
{
MessageBox.Show("SimpleIndexPage.aspx");

if(current_index < templinks.Length-1)
{
current_index++;
templinks[current_index].click();
}

}

}

Thus, we can make sure that we won't call the next element's click() before
the previous one has been loaded and operated yet.
How do you think of this? If you have anything unclear, please feel free to
post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #24

P: n/a
Hi EJ,

Thanks for your reply. Since you mentioned that you failed to apply my
logic to workaround the loop sync problem, would you provide some detailed
info on why it fails or there is any other requirements prevent it ?

Also, I still think the simplest and convenient means is to call the next
element at the end of the previous element's document_complete event. As
for any other means, you may have a look at the WaitHandle class under the
Sytem.Threading namespace.

#WaitHandle Class
http://msdn.microsoft.com/library/en...ThreadingWaitH
andleClassTopic.asp?frame=true

#WaitHandle.WaitOne Method
http://msdn.microsoft.com/library/en...ThreadingWaitH
andleClassWaitOneTopic.asp?frame=true

It can help block the current thread for sync with another via a certain
signal.
Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #25

This discussion thread is closed

Replies have been disabled for this discussion.