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

G

Guest

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
 
S

Steven Cheng[MSFT]

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/simplebrowserformfc.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
 
S

Steven Cheng[MSFT]

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 = 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
 
S

Steven Cheng[MSFT]

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-us/cpref/html/frlrfSystemThreadingWaitH
andleClassTopic.asp?frame=true

#WaitHandle.WaitOne Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemThreadingWaitH
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
 

cvk

Joined
Jul 29, 2006
Messages
2
Reaction score
0
loading windows user control on asp.net page

Hi steven
i have similar requirement as in the above thread. i had created a windows user control which i want to show on my web page. but iam getting a plain area where i had placed my user control. on doing IEDebug as mentioned by you i had got these error in the log file

Microsoft.IE.SecureFactory: System.Security.SecurityException: Request for the permission of type System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.

Server stack trace:
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
at System.Activator.CreateComInstanceFrom(String assemblyName, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
at System.AppDomain.CreateComInstanceFrom(String assemblyFile, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at System.AppDomain.CreateComInstanceFrom(String assemblyFile, String typeName, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
at Microsoft.IE.SecureFactory.CreateInstanceWithSecurity(Int32 dwFlag, Int32 dwZone, String pURL, String uniqueIdString, String link, String licenses)

Please let me know how to resolve this error.

Regards
cvk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top