Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2011, 05:42 PM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default VB InnerHTML for my form?

I have the following code in my webpage:

Code:
<script runat="server">

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim loginID = "------"
        Dim transactionKey = "------"
        Dim amount = "19.99"
        Dim description = "Sample Transaction"
        Dim label = "Submit Payment"
        Dim testMode = "false"

        amountSpan.InnerHtml = amount
        descriptionSpan.InnerHtml = description

'........
'.........
'.........
'blah blah
'more code
'blah blah blah............


End Class

</script>

    <title>Title Text</title>
</head>
<body>
Amount: <span runat="server" id="amountSpan"></span><br />
Description: <span runat="server" id="descriptionSpan"></span><br />

    <form id="simForm" runat="server" method='post' action='https://test.authorize.net/gateway/transact.dll'>
        <input id="HiddenValue" type="hidden" value="Initial Value" runat="server" />
        <input type='hidden' runat="server" name='x_login' id='x_login' />
        <input type='hidden' runat="server" name='x_amount' id='x_amount' />
        <input type='hidden' runat="server" name='x_description' id='x_description' />
        <input type='hidden' runat="server" name='x_invoice_num' id='x_invoice_num' />
        <input type='hidden' runat="server" name='x_fp_sequence' id='x_fp_sequence' />
        <input type='hidden' runat="server" name='x_fp_timestamp' id='x_fp_timestamp' />
        <input type='hidden' runat="server" name='x_fp_hash' id='x_fp_hash' />
        <input type='hidden' runat="server" name='x_test_request' id='x_test_request' />
        <input type='hidden' name='x_show_form' value='PAYMENT_FORM' />
        <input type='submit' runat="server" id='buttonLabel' />
    </form>

and i get this error message:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30469: Reference to a non-shared member requires an object reference.

Source Error:


---------------------------------------------
Line 51:
Line 52: amountSpan.InnerHtml = amount
Line 53: descriptionSpan.InnerHtml = description
Line 54:
---------------------------------------------


It seems to have a problem with "InnerHtml" but I don't understand why. The document is saved as .aspx, and I'm pretty sure it's an HTML form. does that make a difference? What am I missing?

Last edited by MtheK; May 27th, 2011 at 05:44 PM..
Reply With Quote
  #2 (permalink)  
Old May 28th, 2011, 05:10 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In ASP.NET, controls must be placed in a form with a runat="server" attribute, which you seem to be missing. In Visual Studio, create a new Web Form to see the general layout. Then add your span inside this form. Then add your other form to the same page (but below the ASP.NET form). You can't nest forms in HTML, and ASP.NET requires you to have a form that complies to its rules, and by adding adding the second form below the first one, you can satisfy both rules.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old May 28th, 2011, 12:29 PM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default

Thansk for getting back to me so quickly

I'm pretty sure that my form had a runat="server" attribute, but I went ahead and tried your instructions, however I may have missed something or not done something right, because I still have the same problem.

Below is the code with the changes I made:

Code:
<%@ import namespace="System.Security.Cryptography" %>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
'Imports System.Security.Cryptography -required for fingerprint calculation-

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' start by setting the static values
        Dim loginID = "----------"
        Dim transactionKey = "------------"
        Dim amount = "19.99"
        Dim description = "Sample Transaction"
        ' The is the label on the 'submit' button
        Dim label = "Submit Payment"
        Dim testMode = "false"
'
'.......code that was considered unneccessary to include........
'

End Class
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>


    <form id="form1" runat="server">
    <div>
    Amount: <span runat="server" id="amountSpan"></span><br />
    Description: <span runat="server" id="descriptionSpan"></span><br />

    <form id="simForm" runat="server" method='post' action='https://test.authorize.net/gateway/transact.dll'>
        <input id="HiddenValue" type="hidden" value="Initial Value" runat="server" />
        <input type='hidden' runat="server" name='x_login' id='x_login' />
        <input type='hidden' runat="server" name='x_amount' id='x_amount' />
        <input type='hidden' runat="server" name='x_description' id='x_description' />
        <input type='hidden' runat="server" name='x_invoice_num' id='x_invoice_num' />
        <input type='hidden' runat="server" name='x_fp_sequence' id='x_fp_sequence' />
        <input type='hidden' runat="server" name='x_fp_timestamp' id='x_fp_timestamp' />
        <input type='hidden' runat="server" name='x_fp_hash' id='x_fp_hash' />
        <input type='hidden' runat="server" name='x_test_request' id='x_test_request' />
        <input type='hidden' name='x_show_form' value='PAYMENT_FORM' />
        <input type='submit' runat="server" id='buttonLabel' />
    </form>

    </div>
    </form>
</body>
</html>

Also, although I used visual basic to see what the web form would look like, as per your instructions, I am using microsoft expression web as my editor. I probably should have mentioned also that the page renders when I preview it in visual studio, but not in microsoft expression web.
Reply With Quote
  #4 (permalink)  
Old May 28th, 2011, 01:03 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You have two forms nested within each other (e.g a form in a form) which is not supported. Also, yo can't have two forms with a runat attribute....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old May 28th, 2011, 03:43 PM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default

Sorry for the misunderstanding. I removed the extra form tag, but that's how it was before. It had the runat="server" before as well, and still has it now. same issue.
Reply With Quote
  #6 (permalink)  
Old May 29th, 2011, 06:22 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

If you want to "talk" to ths span, it needs to be in the form with a runat attribute. And since you can only have one server side form, you need to remove the attribute from the other form. E.g.

<form runat="server" .... >

</form>
<form>

<form>

But what exactly are you trying to accomplish? There may be other ways to do this. For example, you could build up the second form from code, or you could host it inside an iframe for example.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old May 30th, 2011, 11:07 AM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2010
Posts: 21
Thanks: 4
Thanked 1 Time in 1 Post
Default

I'm trying to get the sample code to run outside of visual studio.

The spans aren't actually as important to me as the form with the inputs I'm trying to post.

I've tried removing the spans altogether, and it comes up with the same error, but in regards to these lines:

Code:
        'Update the fields in the actual form 
        x_login.Value = loginID
        x_amount.Value = amount
        x_description.Value = description
        buttonLabel.Value = label
        x_test_request.Value = testMode
        x_invoice_num.Value = invoice
        x_fp_sequence.Value = sequence
        x_fp_timestamp.Value = timeStamp
        x_fp_hash.Value = fingerprint
    End Sub
This code being relevant to it:

Code:
Partial Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' start by setting the static values
        Dim loginID = "9u34JfHk"
        Dim transactionKey = "2S4Eg77RWAqq472L"
        Dim amount = "19.99"
        Dim description = "Sample Transaction"
        ' The is the label on the 'submit' button
        Dim label = "Submit Payment"
        Dim testMode = "false"

...

        'Update the fields in the actual form 
        x_login.Value = loginID
        x_amount.Value = amount
        x_description.Value = description
        buttonLabel.Value = label
        x_test_request.Value = testMode
        x_invoice_num.Value = invoice
        x_fp_sequence.Value = sequence
        x_fp_timestamp.Value = timeStamp
        x_fp_hash.Value = fingerprint
    End Sub

...

     End Function

...

End Class
What I want to do is be able to post my variables to the test webpage specified in the form. I am stuck on this approach because it was in the sample code.
Reply With Quote
  #8 (permalink)  
Old May 30th, 2011, 11:17 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You probably get the same error because you now removed the runat attribute from the other form.

An ASPX page by default posts back to itself, so if you need to post back to another site, you need to create a separate, non server-side form. As i suggested earlier, you could build up the second form as a string frm code behind. Alternatively, you could look into "cross page postbacks". Google has a lot of information on this subject.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set a form as startup form in vb.net 2.0 mallikalapati .NET Framework 2.0 1 February 21st, 2008 09:19 AM
Problem with IE's innerHTML and <form> tags??!?! nebulus Javascript 1 February 15th, 2006 05:08 PM
Urgent VB form Migration to VB.net form kvenkat_2k1 Pro VB.NET 2002/2003 1 December 7th, 2005 04:58 PM
Getting InnerHtml ghari Javascript 3 January 3rd, 2005 12:06 PM
innerHTML interrupt Javascript How-To 6 July 22nd, 2004 02:18 PM



All times are GMT -4. The time now is 06:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.