How to Control a Browser From Vb.net

Anyone building professional Web pages quickly understands that the only effective way to control Web browser behavior is through JavaScript. This is the native language of all browsers. Microsoft's Visual Studio provides a number of tools to make this task easier. From code editors and debuggers to built in AJAX support and custom controls, a Visual Basic programmer can avoid much of the JavaScript frustration. Here are a few options for VB.Net developers who want to customize browser behavior.

Things You'll Need

  • Microsoft Visual Studio or Visual Basic Express 2010
Show More

Instructions

    • 1

      Use client side scripting. Embed JavaScript functions within the HTML code with the SCRIPT tag. To call these functions, use the onLoad attribute of the BODY tag or the onClick, onChange, onBlur or other event handling attributes of the input tag. Here is a simple Hello World example using this technique.

      <HTML>

      <HEAD>

      <TITLE>Testing</TITLE>

      <SCRIPT language="JavaScript">

      function btn_click()

      { alert ("Hello world");

      }

      </SCRIPT>

      </HEAD>

      <BODY>

      <INPUT type="button" value="Test" onClick='btn_click()' />

      </BODY>

      </HTML>

    • 2

      Use ClientScript.RegisterStartupScript to call JavaScript functions when the page loads. RegisterStartUpScript can be called anywhere in your server side Visual Basic code. It sends JavaScript code to the browser along with the new HTML page, then adds it to the onLoad event. Once the page loads, the JavaScript code executes immediately. Here is a sample ServerClick event handler that asks the user whether they want to proceed to the next page using the JavaScript confirm function.

      Public Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.ServerClick

      Dim scrpt as string = "<script language='JavaScript'>

      Scrpt &= "if (confirm('Do you want to continue?')) "

      Scrpt &= "window.location = 'nextPage.aspx';"

      Scrpt &= "</script>"

      ClientScript.RegisterStartupScript(Me.GetType, "QuestionScript", scrpt)

      End Sub

    • 3

      Use ASP.Net AJAX. AJAX mixes XML based Web services on the server side with JavaScript on the browser to pass messages back and forth behind the scenes. Although this may be beyond the abilities of a beginning Web developer, Microsoft has created a number of built-in features that make it accessible to Visual Basic programmers.

    • 4

      Use AJAX controls. Another way to use AJAX is through custom controls provided by Microsoft or other developers. Once these controls get downloaded to your computer, they drag and drop onto the Web form designer in the same manner as any other text box or button. Controls include dynamic menus, text boxes with built in auto-completion, paging lists, behind the scenes file upload and many others. Check the reference below for Microsoft's AJAX control add-in or do a Google search for other vendor's controls.

Tips & Warnings

  • Take the time to really learn JavaScript. Professional grade websites need the dynamic interaction JavaScript provides.

Related Searches:

References

Comments

Related Ads

Featured