Click here to Skip to main content
15,884,099 members
Articles / Web Development / ASP.NET

JavaScript code generator tool for Visual basic developers

Rate me:
Please Sign up or sign in to vote.
4.25/5 (5 votes)
29 Feb 2016CPOL2 min read 11.5K   269   6  
A Windows application tool that generate JavaScript code for a specific ASP server controls (Textbox, CheckBox and radio button)

Image 1

Introduction

I have found this tool in my old folders and I feel it is good to share with you.

Ten years ago, I was working in a company for developing a web application using VisualBasic.NET.
At that time we use to write some simple JavaScript functions to reduce post back times and reduce page shaking and improve performance.

Many of team member’s faces difficulties to deal with JavaScript since they came from visual basic windows development background.

At that time, I have developed this tool as a windows application to generate JavaScript code for a specific controls Text box, check box and radio button using visual interface.

Background

JavaScript and Web development basic understanding.

Using the tool

Let us have a scenario that we need a JavaScript function to enable/disable text boxes based on user selection.

  1. Determine the owner control for JavaScript function.

    Image 2
    • Control Type dropdown:
      The control type dropdown list provides a listing of control types supported by this tool; the user selects the type of control that will have this method.
    • Control Event dropdown:
      The control event dropdown list provides a listing of control events supported by this tool; the user selects the event of control that will render the method.
    • Control Name Textbox:
      The control name Textbox; the user enters the name of control that will have the method.
    • Start Method Button:
      The start method button; will start writing the method for the selected control.
    • Reset Button:
      The reset button; enable the user to begin new method.
  2. Write VB statement for the selected control

    Image 3
     
  3. This step starts after pressing start method button; now you write VB statement by choosing the buttons simple statement or IF statement.

    Image 4
    Simple Statement Dialog.

    Image 5
    IF Statement Dialog.
     
  4. press "Generate JScript Code" to generate the java script code in the text box near it.

    Image 6
     
  5. Copy to the Clipboard:
    Add the copied JavaScript code between HTML header tags, then add the event to the owner control as below
    HTML
    <head  runat="server">
        <title></title>
    <script lang="javascript" type="text/javascript" >
    function chkTest_onclick()
    {
    // Add to your Control tag onclick="chkTest_onclick()"
    
        var JtxtTest1;
        JtxtTest1=document.getElementById("txtTest1");
        JtxtTest1.disabled=true;
    
    }
    </script>
    </head>
    <body>
        <form id="form1"  runat="server">
            <div>
                <asp:CheckBox ID="chkTest" runat="server" onclick="chkTest_onclick()" />
                <asp:TextBox ID="txtTest1" runat="server"></asp:TextBox>
            </div>
        </form>
    </body>
    </html>

Using the code

I have deepened on saving the user inputs on public Arrays
VB
Public arrCode() As String
Public arrIF() As String
Public arrIFscript() As String
Public arrScript() As String
I have generate the code by reading from array and generating a string using StringBuilder
VB
Public Sub ShowTheScript()
        Try
            Dim sb As New StringBuilder
            Dim intCounter As Integer = 0
            rtxtScript.ForeColor = Color.Blue
            For intCounter = 0 To arrCode.Length - 1
                If intCounter < arrCode.Length - 1 AndAlso arrCode(intCounter + 1) = "     Then" Then
                    sb.Append(arrCode(intCounter))
                Else
                    sb.Append(arrCode(intCounter))
                    sb.Append(Environment.NewLine)
                End If
            Next
            sb.Append(Environment.NewLine)
            sb.Append("End Sub")
            rtxtScript.Text = sb.ToString
        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "Undefined Error")
        End Try
End Sub

Points of Interest

As I mentioned earlier I developed this tool long time back and I think it will be good for visual basic beginners or it can give an idea for advance developer on how the code generating tools could work.

History

Version 1.0.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Saudi Arabia Saudi Arabia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --