Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the variable in the code behind

Status
Not open for further replies.

trickytr

Programmer
Joined
May 21, 2005
Messages
6
Location
TR
Hi everyone,

My problem is using the value of a variable from the codebehind page in an html tag.
I have got the html code on default.aspx for example
and there is a variable in default.aspx.vb called THISPAGE.
And in the HTML code I want to use this string value in a form tag like this:

<form method="post" action="<% =THISPAGE %>">

But when I run the page I got an error message that THISPAGE should be declared although I have declared it in the codebehind page.

Thanks a lot.
 
How is THISPAGE Declared? Make sure it's public
 
I made the scope of variable Public in default.aspx.vb before but still I got the error message that it is not declared.
 
You shouldn't really set attributes by including script tags. The correct way to do it would be to:

1) Add a reference to your Form in the code-behind. e.g. if you Form tag had an ID of Form1 then add:
Code:
    Public WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm

2) On your Page Load, use Attributes.Add to add the action attrribute. e.g.
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim strPage As String = "Page2.aspx"
        Form1.Attributes.Add("action", strPage)
    End Sub

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Thank you for your answer it really helped.
But I have got an another problem. I want to use vb code and html on the same page without using an codebehind page.
But I have to add this codes

Imports System.Data.SqlClient
Imports System.Web.Security

And I could not do this on the aspx page it only worked on the codebehind page.Is there any way to import these in the aspx page without using code behind.

Thanks a lot
 
<% @ import namespace="System.Data"%>
<% @ import namespace="System.Data.SqlClient"%>

Add these code at the top of your page...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top