How to call a vb script funtion in form load ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bijeshputhalath
    New Member
    • Jan 2010
    • 3

    How to call a vb script funtion in form load ??

    Hi,

    I am a new bi in asp...
    I need to call a function in asp with vb script in form load...without button fire.

    please give sample code...

    Thanks and Regards,



    Bijesh
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2
    do you mean?

    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    MyFunction()
    
        End Sub

    Comment

    • bijeshputhalath
      New Member
      • Jan 2010
      • 3

      #3
      Hi,

      Actually I have currency conversion coding from INR to USD .But it will execute in Button click only...ie we need to give the amount in INR in textbox.and while clicking submit button , it wil convert the amount into USD and will show the output.

      Instead of button click event, I need to show the output while the page loaded. I set the input as static(ie textbox value I set to some value).so by taking that input it will execute and show the corresponding amount in USD.


      The following is the code....I need to call a function for this conversion...



      <%@ language="VBScr ipt" %>

      <html>
      <head>
      <title>Curren cy Server ASP Example 2</title>
      </head>

      <body>
      <!-- declare application object -->
      <%
      Const curncsrvReturnR ateString = 1
      Const curncsrvReturnR ateNumber = 2
      Dim objApplication, objCurrencies,U RL


      Set objApplication =Server.CreateO bject("Currency Server.Applicat ion")
      Set objCurrencies = objApplication. ActiveCurrencie s


      %>
      &nbsp;






      <table border=0>


      <td style="visibili ty:hidden" ><%= objCurrencies.C ount %></td></tr></table><br>

      <!-- currency conversion form -->
      <form onload=csexampl e2.asp method="POST">


      <table>
      <tr>
      <td> </td>
      <td><select name=CurrFrom style="HEIGHT: 22px; WIDTH: 166px;visibilit y:hidden; ">
      <% For i = 1 To objCurrencies.C ount
      if Request.Form("C urrFrom") = "INR" then %>
      <option selected><%="IN R"%>
      <% else %>
      <option><%="INR "%>
      <% end if%>
      <% Next %>
      </select>



      </td>
      <td> </td>
      <td><select name=CurrTo style="HEIGHT: 22px; WIDTH: 166px;visibilit y:hidden;">
      <% For i = 1 To objCurrencies.C ount
      if Request.Form("C urrTo") = "USD" then %>
      <option selected><%= "USD"%>
      <% else %>
      <option><%= "USD"%>
      <% end if%>
      <% Next %>

      </select></td>
      </tr>
      <tr>
      <td>Amount to convert:</td>
      <td>
      <input name=FromValue value="100">


      </td>
      <td></td>
      <td></td>
      </tr>
      <tr>
      <td>
      <input type="submit" name="Convert" value=Convert>
      </td>
      <td>
      </td>
      <td></td>
      <td></td>
      </tr>
      <tr>
      </tr>
      <tr>


      <% dim ToValue %>
      <% dim FromValue %>
      <% FromValue=Reque st.Form("FromVa lue") %>

      <!-- validation of input data -->
      <% if (FromValue > "") and (IsNumeric(From Value)) then
      ToValue = objApplication. Convert(Request .Form("CurrFrom "), Request.Form("C urrTo"), Request.Form("F romValue"), true, ". ", curncsrvReturnR ateString)
      end if %>
      <!-- empty -->
      <% if FromValue = "" then ToValue = "" end if %>
      <!-- alpha -->
      <% if not IsNumeric(FromV alue) then
      FromValue = ""
      ToValue = ""
      end if
      %>
      <td>Result:</td><td><input name=ToValue Value="<%=ToVal ue%>"></td>
      <td></td>
      <td></td>
      <!-- free resources -->
      <% Set objApplication = Nothing %>


      </tr>
      </table>
      </form>
      </body>
      </html>

      Comment

      • yarbrough40
        Contributor
        • Jun 2009
        • 320

        #4
        just give your function a name like "MyFunction " then I believe you can call it using something like:

        onLoad=”MyFunct ion()”

        Comment

        • bijeshputhalath
          New Member
          • Jan 2010
          • 3

          #5
          Hi,

          If I need to call this in form load or page load???

          Please give a sample code...How to call?

          How the function look like??

          Thanks and Regards
          Bijesh

          Comment

          • yarbrough40
            Contributor
            • Jun 2009
            • 320

            #6
            I'm a .net programmer so I apologize if I can't be of further assistance. but it would seem to me that you could build a function (use 'sub') and then type "call" to call it. place the code within the body of the page. the sub procedure will run when the page loads.

            Code:
                    <script type="text/vbscript">
            
            sub MySub()
            dim i
            i = 0
            End Sub
            
            call MySub()
            
            </script>

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              OK, I need to clarify, and I'm not sure I follow your explanation of the problem.
              1- Are you trying to run client-side VBScript? Although it is technically possible, I think only Internet Explorer ever supported that, and it was only standard in pre-IE7. Most people use Javascript to execute code on the browser. Nevertheless, if that is what you are trying to do, I can try to help you.
              2- Are you trying to call an ASP function after the page is sent to the client? That will not work, the ASP script is completely finished by the time it is sent to the browser. Calling an ASP function after the browser receives the page is like trying to get a factory option installed on your car AFTER you receive it. If you want the function to execute while the form is being BUILT, that is another question.

              Jared

              Comment

              Working...