?
Solved

Get vbhtml code to execute from html - razor

Posted on 2014-07-16
7
Medium Priority
?
457 Views
Last Modified: 2014-07-19
Hi Experts.  

I have code in the code section of my vbhtml, say

dim a as integer
dim b as integer
dim result as integer = a + b

a and b are dynamic so I want to add a button to the html that will show "result" in a label when the
button is clicked to update result

I think I'm trying to say I want an html button that will activate code

Any Ideas?
0
Comment
Question by:PNRT
  • 4
  • 3
7 Comments
 
LVL 5

Expert Comment

by:Jeroen Timmermans
ID: 40198806
<form>
<input name="valueA">
<input name="valueB">
<input type=submit>
</form>

and in your code:
a = Request.Form("valueA");
b = Request.Form("valueB");
dim result as integer = a + b;

Untested code, just a crude guideline to where you seem to be going
0
 
LVL 2

Author Comment

by:PNRT
ID: 40198907
Many thanks, I get the input boxes and the submit button which I assume adds up a and b, but how would I show "result" on the page.  I don't get result when clicking the button.  I have this so far     Thanks again

 dim a As Integer = Request.Form("valueA")
 dim b As Integer = Request.Form("valueB")
 dim result as integer = a + b

<form>
 <input name="valueA">
 <input name="valueB">
 <input type=submit>
 </form>
0
 
LVL 5

Expert Comment

by:Jeroen Timmermans
ID: 40198911
<div>@{result}</div>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:PNRT
ID: 40198919
No luck I'm afraid.
@result shows zero when the page loads.  
Entering values and clicking refreshes the page, empties a and b boxes and then still shows zero
Maybe the page refresh is a problem?
0
 
LVL 5

Expert Comment

by:Jeroen Timmermans
ID: 40198928
Try this:
In your controller:
Public Function Index(ByVal a As Integer?, ByVal b As Integer?) As ActionResult
            dim a as integer
dim b as integer
dim result as integer = a + b
            Return View(result)
        End Function

Open in new window


In your Index.vbhtml:
@ModelType Integer
....
<div>@{Model}</div>

Open in new window

0
 
LVL 2

Author Comment

by:PNRT
ID: 40198938
Sorry, how would I call the function?
0
 
LVL 5

Accepted Solution

by:
Jeroen Timmermans earned 2000 total points
ID: 40198944
As you would any other action.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

862 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