From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

PLS HELP: ASP.NET web app (using Measurement Studio 6)

Has anyone got any of the controls in Measurement Studio 6 working on an ASP.NET webform? (knob, slider, etc..) I can get the NI control to appear but CANNOT SET the knob value or retrieve it in code. I'm a VB guy using VBScript and ASP.NET. Thanks!
0 Kudos
Message 1 of 12
(5,957 Views)
How are you trying to reference the value in your code? Are you trying to access the value on the server or the client? ActiveX UI controls that are added to a web form are client-side controls, hence they are not instantiated on the server and cannot be accessed from server code like the ASP.NET HtmlControl or WebControl UI controls can. Accessing ActiveX controls on the client in code is the same in ASP.NET as it is in ASP. For example, this has a knob control with a button next to it that will set the value of the knob to 5 when you click the button:















For additional information, see the Microsoft Knowledge Base article HOW TO: Host ActiveX Controls in a Web Form.

- Elton
0 Kudos
Message 2 of 12
(5,878 Views)
I'm new at ASP.NET (currently a VB programmer). Do you know what is wrong with this code? Simple form: 1 button and 1 knob.

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="niApp1.WebForm2"%>



WebForm2











:
:






0 Kudos
Message 3 of 12
(5,880 Views)
This is kinda strange, but if you move the object tag so that it's not nested in the form tag, the code will work as it's written in your example. If you want to keep the knob in the form tag, this code will work instead:

Sub OnButtonClick()
Dim knob
Set knob = document.getElementById("Knob")
knob.Value = 5
End Sub

I'm not sure why there's different behavior for the ActiveX control within the form tag - it seems like to me that it should work the same either way via the direct reference that's specified by the id attribute.

- Elton
0 Kudos
Message 4 of 12
(5,880 Views)
Also, I noticed in the code that you posted that you're using params in the object tag. If all you want to do is set the value, the easiest way to do this would be to set the corresponding param tag. If you're using the VS.NET WebForm designer or ASP.NET Web Matrix, the designer will generate several param tags. Look for the one that looks like this:



Change the value attribute to what you want the value to be and that will automatically do the same thing that the code above was doing when the page loads. For example, to set it to 5 as in the code above:



- Elton
Message 5 of 12
(5,880 Views)
Elton,

Your help has been invaluable. I actually got it working! I have a text box (which I put a value in), click the button, and the knob changes!

Advancing further...

Let's say I want to change the range (min, max) of the knob "on the fly" (or some other property for that matter). The min/max values will be coming from 2 text boxes. I would assume that I need to find the correct PARAM and change the VALUE.

1. My question is what's the best way to do this? (Being that I'm new to ASP.NET - I'm a VB guy.)

2. Later on all of these values (min, max, value, etc...) will be coming from a SQL database. So, I assume I will be scripting using ADO.NET to get the values. Then, the values will be put in the correct PARAM. Is this correct?


3. Lastly, when do I use server scripting vs client scripting (and visa versa), and server controls vs client controls? What are the determing factors? (I know that ActiveX / Com controls HAVE to be client controls, but don't know the reasoning behind it.)

Thanks so much for your help!
0 Kudos
Message 6 of 12
(5,880 Views)
2 additional questions:
1. If I use a webform (with gauge control, etc..) do my clients need to download anything special (ocx, .NET framework, etc..) or just use an up to date browser?
2. I would like to spin the gauge and the value reflect (real-time) in a text box. Any ideas?
0 Kudos
Message 7 of 12
(5,880 Views)
1.) It depends on if you want to update it on the server or the client. If it's on the server, then you could rebuild the param tags, but this wouldn't happen until the form is posted back to the server. If it's on the client, you would probably want to have event handlers for the textbox onblur or onchange events, then set the value via script code on the client.

2.) You could do this by dynamically building the object tag on the server. In your web form, you would probably want to do this by replacing the object tag with and leave it empty, then at run-time build up your object tag via HtmlTextWriter, and then set the value of the literal control from what you've built up in the HtmlTextWriter. For example:

Imports System.Web.UI
Imports System.IO

' ...

Dim buffer As StringWriter
Dim writer As HtmlTextWriter

Try
buffer = New StringWriter
writer = New HtmlTextWriter(buffer)

writer.AddAttribute(HtmlTextWriterAttribute.Id, "knob")
writer.AddAttribute("classid", "clsid:D940E4D2-6079-11CE-88CB-0020AF6845F6")
writer.RenderBeginTag(HtmlTextWriterTag.Object)
' :
' :
writer.AddAttribute(HtmlTextWriterAttribute.Name, "Value_21")
' NOTE: Add your custom parameter value here
writer.AddAttribute(HtmlTextWriterAttribute.Value, "0")
writer.RenderBeginTag(HtmlTextWriterTag.Param)
writer.RenderEndTag()
' :
' :
writer.RenderEndTag()

' Assuming that you had a LiteralControl member in your code-behind called literal:
literal.Text = buffer.ToString()
Finally
If Not buffer Is Nothing Then
Dim disposable As IDisposable = DirectCast(buffer, IDisposable)
disposable.Dispose()
End If

If Not writer Is Nothing Then
Dim disposable As IDisposable = DirectCast(buffer, IDisposable)
disposable.Dispose()
End If
End Try

3.) It's hard to come up with concise guidelines that can be explained in a few sentences, but in a nutshell it comes down to where do you need your logic to execute. In general you should prefer server controls, but when you need to do something that's specific to the client (for example, interactivity on the client such as changing the value of a control, updating the interface via client-side events, etc), you'll have to use client-side controls/code.

- Elton
0 Kudos
Message 8 of 12
(5,660 Views)
1.) You don't need anything (including the .NET framework) on the client for the server controls. The server controls render themselves as HTML/script such that they will work with HTML 3.2 compliant or above web browsers. For the ActiveX control, though, you will need to get the control on the client.

2.) You'll need a client-side event handler for the knob's PointerValueChanged event, then update the value of the textbox. Here's an example:













- Elton
0 Kudos
Message 9 of 12
(5,880 Views)
Elton,

Great responses as usual. Few questions...

1. You said "For the ActiveX control, though, you will need to get the control on the client." Do I just need to email all the users the OCX then have them register it, using regsvr32.exe? Is that all that is required?

2. When my co-worker pulls up the page (www.go-intech.com/test/knob.aspx) he gets 2 messages: (A) "You have 30 days to evaluate a newer version of this ActiveX control. After 30 days, you can revert back to the licensed version of your control. Contact your local branch office or visit the NI Online Store to upgrade your version of Measurement Studio." and (B) Failed loading mesa.dll. Any ideas what these indicate?

Thanks,
Robert
0 Kudos
Message 10 of 12
(5,880 Views)