2

We had a Visual Studio Website project. We needed a .VBPROJ so I had to convert our Web Site Project to a Web Application Project. I followed several walktrough, did everything well for the conversion :

  • create new webapp project
  • add references
  • copy files (from website to webapp folder)
  • include them in the project
  • click "Convert to Web App".

After all that , i get three identical compilation errors, javascript related with an .ASPX page.

<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile ="~/GAR.master" Inherits="GARWA._Default" Codebehind="Default.aspx.vb" %>

'TableWeekID' is not declared. It may be inaccessible due to its protection level.

<script type="text/javascript" language="javascript"> 
//Very important variable! 
var TableWeekTag = '<%=TableWeekID%>'
var DivYearSmallTableTag = '<%=DivYearSmallTable%>' 
var TableNameTag = '<%=TableNameID%>'

What's the problem here ?

Thanks

4
  • I don't see any JavaScript... Commented Oct 11, 2012 at 14:56
  • I don't think the error comes directly from the javascript lines because the same code is working 100% in the Web Site Type project. It's more because of the conversion and the <%@ Page Language... @%> line. But here's the Javascript related <script type="text/javascript" language="javascript"> //Very important variable! var TableWeekTag = '<%=TableWeekID%>' var DivYearSmallTableTag = '<%=DivYearSmallTable%>' var TableNameTag = '<%=TableNameID%>' Commented Oct 11, 2012 at 14:58
  • 1
    How are you declaring the variable TableWeekID in the code behind? Commented Oct 11, 2012 at 15:26
  • It's not, it's an ASP.NET tag, var TableWeekTag = '<%=TableWeekID%>'. This exact code is working A-1 in the Web Site type of Project but no in this newly Web Application Project. Commented Oct 11, 2012 at 15:36

2 Answers 2

1

You can do it in this way.

Use a Hiddenfield control and store the server variable value in it.
One hidden field for each server variable.
And get the value into the javascript function document.getElementById()

Use the below to POPULATE the serverside input control(s) datavalues first.

ASPX SERVERSIDE CODE

svrTableWeek.Value = TableWeekID
svrDivYear.Value = DivYearSmallTable
svrTableName.Value = TableNameID

Also, if you opt for the SERVERSIDE Inputs then you need the following HTML in your ASP page

USING ASP SERVER CONTROLS FOR HIDDEN VALUES

<asp:HiddenField ID="svrTableWeek" runat="server" /> 
<asp:HiddenField ID="svrDivYear" runat="server" /> 
<asp:HiddenField ID="svrTableName" runat="server" /> 

And if you prefer CLIENTSIDE inputs then use the code below instead of ALL of the above

USING HTML (clientside) CONTROLS FOR HIDDEN VALUES

<input type="hidden" id="svrTableWeek" name="svrTableWeek" value="<%=TableWeekID%>" />
<input type="hidden" id="svrDivYear" name="svrDivYear" value="<%=DivYearSmallTable%>" />
<input type="hidden" id="svrTableName" name="svrTableName" value="<%=TableNameID%>" />

Finally regardless of which of the two above methods you choose, now your ready to re-use those values in your clientside javascript

CLIENT SIDE SCRIPT ROUTINES

<script type="text/javascript" language="javascript"> 
//Very important variable! 
var sTableWeek = document.getElementById('svrTableWeek').value;
var sDivYear = document.getElementById('svrDivYear').value;
var sTableName = document.getElementById('svrTableName').value;

It seems a bit long winded I know, but it should work without issues.

Sign up to request clarification or add additional context in comments.

Comments

0

Try global replacing all of the "~/GAR with "GAR . I just converted a Web Site to a Web App, had similar odd errors, all because the virtual reference to the master page files was no longer correct. My first indicator was a DIV ID that wasn't seen in a code-behind file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.