-
Nov 3rd, 2009, 11:59 AM
#1
Thread Starter
Junior Member
Little help with frames
Hi everyone
What i need to know is how to refresh/load a single frame and not the whole page.
Code:
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
Dim theStatusCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("frame")
For Each curElement As HtmlElement In theStatusCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "main" Then
curElement.GetAttribute("scr").Equals("./BeO/webroot/index.php?module=Launchpad")
'this is where i want to refresh/load the scr in the "main" frame but i dont want to refresh the whole page
End If
Next
Also if anyone knows how i could put this code in an external file and just make a call to it this would be great
so would be like this
External File Name
Code:
Public Sub Login()
'Code for login goes here
End Sub
Then just make a call to it in my Form1.vb
Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Call Login.Sub
System.Threading.Thread.Sleep(2000)
Call Name.Sub
Something like that
Thnx in advance
PureBrit
Will be asking for help a lot please be kind im new at vb
-
Nov 3rd, 2009, 12:35 PM
#2
Re: Little help with frames
To refresh just a single frame, you need to grab that frame, and navigate to its URL again. This may or may not work in all cases, but most pages that even use frames are pretty old now, as frames are somewhat depreciated for website design these days.
So anyways, to do this, basically something like this would work.
Code:
Dim FrameToRefresh = WebBrowser1.Document.Window.Frames(1)
FrameToRefresh.Open(FrameToRefresh.Url, "_self", "", True)
basically you get the frame you want to refresh (in this example, its the second frame since the index starts at 0), then once I get that frame, I call its Open method to open a URL in just that frame, and I pass in the URL that is currently in the frame. I pass in "_self" for the target so it will load the frame in the same spot.
-
Nov 3rd, 2009, 01:03 PM
#3
Thread Starter
Junior Member
Re: Little help with frames
Thanks kleinma
That worked and done just what i wanted it to do.
But how do i stop it refreshing lol it just keeps refreshing over and over again
Will be asking for help a lot please be kind im new at vb
-
Nov 3rd, 2009, 01:07 PM
#4
Re: Little help with frames
You could set a flag (just simple boolean variable) which has an initial value of false. When your code is going to refresh the frame, check this flag, and if it is false, set it to true and then refresh the frame. Then when the routine fires again, your flag is true, no second refresh is done, and that should fix the problem.
-
Nov 3rd, 2009, 01:13 PM
#5
Thread Starter
Junior Member
Re: Little help with frames
Originally Posted by kleinma
You could set a flag (just simple boolean variable) which has an initial value of false. When your code is going to refresh the frame, check this flag, and if it is false, set it to true and then refresh the frame. Then when the routine fires again, your flag is true, no second refresh is done, and that should fix the problem.
/me googles flags lol
na thanks mate you pointing me in the right direction
/me gets his books out and reads about flags
Will be asking for help a lot please be kind im new at vb
-
Nov 3rd, 2009, 01:16 PM
#6
Re: Little help with frames
well flag can mean a few things. In this case it is really just a switch like on or off.
Code:
'THIS SHOULD BE DECLARED AT THE CLASS LEVEL
Dim myFlag as boolean = false
'THIS WOULD BE IN YOUR DOCUMENTCOMPLETED ROUTINE
If myFlag = False then
myFlag = True
'REFRESH FRAME HERE
end if
see, so the flag here ensures the code to refresh the frame only happens once, because you set the flag to true the first time you refresh, so when the routine fires again, it will skip the code since the flag is now true.
-
Nov 3rd, 2009, 01:42 PM
#7
Thread Starter
Junior Member
Re: Little help with frames
Originally Posted by kleinma
well flag can mean a few things. In this case it is really just a switch like on or off.
Code:
'THIS SHOULD BE DECLARED AT THE CLASS LEVEL
Dim myFlag as boolean = false
'THIS WOULD BE IN YOUR DOCUMENTCOMPLETED ROUTINE
If myFlag = False then
myFlag = True
'REFRESH FRAME HERE
end if
see, so the flag here ensures the code to refresh the frame only happens once, because you set the flag to true the first time you refresh, so when the routine fires again, it will skip the code since the flag is now true.
nice one thanks mate i got a bit of code like that out of one of my books
thnx for all your help added to your rep
Will be asking for help a lot please be kind im new at vb
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|