views:

959

answers:

2

Hello, I have a vbscript function which will get a value from ActiveX control IntegriSign1 as shown in the code below.

I have a ASP.net Texbox and ASP.net Button in my asp.net page as show in the code below.

From my GetSignData() function How can I populate txtIntegri1 with SignData Value

Thanks

<script type="text/vbscript" >
 sub GetSignData()
  SignData=window.document.IntegriSign1.GetSignData()
  'window.document.frmIntegriSign.txthashdata.value
  set t1=window.document.getElementById("<%=txtIntegri1.clientID%>") 
  If tl<> null Then
   t1.value=SignData
  else
   msgbox signData
  End If
 end sub
</script>
<asp:TextBox ID="txtIntegri1" runat="server" ></asp:TextBox>
<input type="button" id="btnAccept" name="btnAccept" runat="server" value="Accept " onclick="GetSignData();" />

I am getting an error Object Required txtIntegri

A: 

You can refer to the textbox's ID by modifying your VBScript to include something like this:

<script type="text/vbscript" >
    sub GetSignData()
        ' assign SignData
        ' SignData=window.document.IntegriSign1.GetSignData()

        set txtIntegri = document.getElementById("<%= txtIntegri1.ClientID %>")
        txtIntegri.value = SignData
    end sub
</script>

Assign that to a variable to reference the textbox then assign the desired value to it.

EDIT: as Joel mentioned, your textbox's current visibility prevents any access to it. For the above to work you need to show the textbox.


Here's my working example. One difference is in the onClick event I had to remove the semi-colon ";" to get it to trigger. If you start a new project and drop this in, excluding the "<%@ Page..." declaration at the top, you should be able to see the textbox being updated.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title></title>
    <script type="text/vbscript">
        sub GetSignData()
            signData = "Hello, StackOverflow!"
            set myTextbox = document.getElementById("<%= Textbox1.ClientID %>")
            myTextbox.value = signData
        end sub
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="Textbox1" runat="server" Text="Hello, World!" />
        <input type="button" id="btnAccept" name="btnAccept" runat="server" value="Accept " onclick="GetSignData()" />
    </div>
    </form>
</body>
</html>
Ahmad Mageed
Hi, When I add this I am getting an errorwindow.document.hdIntegriSign1.clientID.value=SignDataObject doesn't suppoert widow.document.hdIntegriSign1 property or method
acadia
@acadia: please update your question with your latest code so we can help you better. I've updated my post to show how to set the txtIntegri1 textbox. The error you mentioned seems to be part of how you get the SignData value.
Ahmad Mageed
Ahmad Mageed, I have updated the code and the error message I am able to get the SignData value correctly but when I try to set the value for the textbox it is throwing object required error. Thanks
acadia
@acadia: I accidentally omitted the double quotes from the getElementById() method. I updated my code to show this and that will fix the object required error. Change it to this (notice the double quotes): set txtIntegri = document.getElementById("<%= txtIntegri1.ClientID %>")
Ahmad Mageed
Other than that I would suggest considering using Javascript instead of VBScript if possible to be compatible across browsers.
Ahmad Mageed
Sorry Ahmad Mageed. It still doesn't work. I updated the code. It directly displays the message instead of populating the textbox. The reason I am using this vbscript is becos of the activex control I am using for signing that that is the only way I can use this.
acadia
@acadia: I've updated my post with my working example that I've tested with. Try it out and it should work for you. Then compare it with what you have and see if there are any adjustments needed that could get your code working. If it still doesn't work then please update your question with your full page, or a small - but complete - sample for others to reproduce the problem.
Ahmad Mageed
+2  A: 

You can't. The Visible="false" property on your textbox means that it isn't rendered to html at all. As far as your browser is concerned, it doesn't exist.

But putting that aside (assuming you have other code that corrects this), you can reference the ID of the control using the .ClientID property as Ahmad Mageed suggests.

Joel Coehoorn
Good catch :) ... 15 chars
Ahmad Mageed