Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Webbrowser enable/disable goback and goforward

Posted on 2004-10-08
6
1,024 Views
Last Modified: 2008-01-09
I've got a webbrowser control in my application and now how too navigate and goback a page and goforward a page.

Now I want too disable the go back button in my program if there is no page to go back too and i want too disable the forward button in my program if there is no page too go forward too. How can I check if there are pages too go back or forward too ?
0
Comment
Question by:oostwijk
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12258315
Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2
From MS:

"The WebBrowser control supports a CommandStateChange event, which is fired whenever the Forward or Back buttons need to be enabled or disabled. "

http://support.microsoft.com/default.aspx?scid=kb;EN-US;163282

' A Visual Basic application can also implement this
' functionality in this manner:  

Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2

Private Sub WebBrowser_CommandStateChange(ByVal Command As Long,ByVal Enable As Boolean)

       Select Case Command

           Case CSC_NAVIGATEBACK
               YourBackButtonName.Enabled = Enable

           Case CSC_NAVIGATEFORWARD
              YourForwardButtonName.Enabled = Enable

       End Select

End Sub
0
 

Author Comment

by:oostwijk
ID: 12261331
hmm, this is difficult for me too understand.. im sort of a VB newbie...

I understand that it checks if the back or forward button needs too be enabled.

Where in the code can I disable the buttons if the back or forward function isnt available ?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12261996
The webbrowser control fires the CommandStateChange event when the enabled state of the command buttons you are using to control navigation need to be changed.

For example if youur webbrowser control's name is WebBrowser1 then the event would be:

Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long,ByVal Enable As Boolean)
           Select Case Command

           Case CSC_NAVIGATEBACK
               YourBackButtonName.Enabled = Enable '<<< This enables or disables the button.  
                                                                                 Replace "YourBackButtonName" with the name of your button

           Case CSC_NAVIGATEFORWARD
              YourForwardButtonName.Enabled = Enable

       End Select
End Sub

And if the button you use to navigate forward is called cmdNavFwd, then to navigate forward in the click event:

Private Sub cmdNavFwd_Click()
    Webbrowser1.GoForward
End Sub
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:oostwijk
ID: 12265161
ok, here is what I got, I've placed an webbrowser control on the form along with 2 commandbuttons named back and forward. And this is the code I have:

=========================================

Private Const CSC_NAVIGATEFORWARD As Long = 1
Private Const CSC_NAVIGATEBACK As Long = 2

Private Sub WebBrowser_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)

       Select Case Command

           Case CSC_NAVIGATEBACK
               back.Enabled = Enable

           Case CSC_NAVIGATEFORWARD
               forward.Enabled = Enable

       End Select

End Sub

Private Sub back_Click()
WebBrowser1.GoBack
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate "http://www.cnn.com"
End Sub

Private Sub forward_Click()
WebBrowser1.GoForward
End Sub

============================================

If you try this code you can see nothing at all happens with the commandbuttons, they are not enabled or disabled. What am I doing wrong ?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 12265885
Private Sub WebBrowser1_CommandStateChange(ByVal Command As Long, ByVal Enable As Boolean)
----------------------------^ Don't forget the 1, Webbrowser1 is the name of your control.

Try correcting this and see if it works for you.

In the code edit window there is a dropdown box upper left which lists objects on your form.  Select Webbrowser1, and then the dropdown box upper right will list all the available events for the control.

Hope it helps!
0
 

Author Comment

by:oostwijk
ID: 12266325
That was it, thank you very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question