• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Setting session variables from Javascript

The following fields are setup from a javascript that displays a tabbed menu:

<form name='tabform' method='post' action='somepage'>
<script type='text/javascript'>
var pane1 = '<asp:TextBox size='25' id='headline' runat='server' /><p> <asp:TextBox size='25' id='aboutme' runat='server' /><p> <asp:TextBox size='25' id='idliketomeet' runat='server' /><p><asp:TextBox size='25' id='interests' runat='server' />'<p><asp:TextBox size='25' id='music' runat='server' /><p><asp:TextBox size='25' id='tv' runat='server' /><p><asp:TextBox size='25' id='books' runat='server'<p><asp:TextBox size='25' id='heroes' runat='server'/><p><asp:Button OnClick="Button1_Click" Text="Submit" runat="server"  />';

//Note these are all on the same line in VS.

My codebehind:

void Button1_Click(Object sender, System.Web.UI.ImageClickEventArgs e)
            {
                  string customerId = Session["customerid"].ToString();

                  Session["headline"] = headline.SelectedItem.Text;
                  Session["aboutme"] = aboutme.SelectedItem.Text;
                  Session["idliketomeet"] = idliketomeet.SelectedItem.Text;
                  Session["interests"] = interests.SelectedItem.Text;
                  Session["music"] = music.SelectedItem.Text;
                  Session["movies"] = movies.SelectedItem.Text;
                  Session["television"] = television.SelectedItem.Text;
                  Session["books"] = books.SelectedItem.Text;
                  Session["heroes"] = heroes.SelectedItem.Text;
           

                  // Redirect browser back to shopping cart page
                  Response.Redirect("ConfirmChanges.aspx");
            }

I get the error:

E:\Inetpub\wwwroot\StoreCSVS\ProfileSettings.aspx.cs(27): The type or namespace name 'headline' could not be found (are you missing a using directive or an assembly reference?)


How can I get my codebehind to recognize these fields? Here's the entire page with javascript below for further clarification:


<%@ Page language='c#' Codebehind='ProfileSettings.aspx.cs' AutoEventWireup='false' Inherits='IBuySpy.ProfileSettings' %>
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN' >
<html>
      <head>
            <title>ProfileSettings</title>
            <meta name='GENERATOR' Content='Microsoft Visual Studio 7.0'>
            <meta name='CODE_LANGUAGE' Content='C#'>
            <meta name='vs_defaultClientScript' content='JavaScript'>
            <meta name='vs_targetSchema' content='http://schemas.microsoft.com/intellisense/ie3-2nav3-0'>
            <style type='text/css'>

.pane {
  display : none;
  }
td.tabs {
  border-top : medium outset green;
  border-left : medium outset green;
  }
div.tabs {
  background-color : #00ffff;
  cursor : hand;
  }
</style>
<!-- following style not necessary -->
<style type='text/css'>
body {
  background-color : #eeccee;
  }
input.txt {
  position : absolute;
  left : 120px;
  }
input.chk {
  position : relative;
  }
</style>

<script type='text/javascript'>
var currentPaneStyle = 0;
var currentTab = 0;

function tabstrip()
{
   this.tabs = new Array();
   this.add = addTab;
   this.write = writeTabstrip;
}

function tab(caption,content)
{
  this.setId = setId;
  this.caption = caption;
  this.content = content;
  this.write = writeTab;
  this.writeContent = writePane;
}



function addTab(tab)
{
  tab.setId('tab' + this.tabs.length);
  this.tabs[this.tabs.length] = tab;
}

function setId(id)
{
  this.id = id;
}

function initiate()
{
  var div = document.getElementById('tab0');
  showPane(div);
}

function showPane(div)
{
  if(currentTab != 0)
  {
    currentTab.style.backgroundColor = '#00ffff';
  }
  div.style.backgroundColor = '#ccccff';
  currentTab = div;

  if(currentPaneStyle != 0)
    currentPaneStyle.display = 'none';
  var paneId = 'pn_' + div.id;
  var objPaneStyle = document.getElementById(paneId).style;
  objPaneStyle.display = 'block';
  currentPaneStyle = objPaneStyle;
}

function SubmitForm()
{
   window.alert('Form submitted.  This would normally take you to another page');
   // normally, you would here check the form and submit it.
   // if the form has the name 'tabform', then it is submitted
   // with tabform.submit();
}

function writePane()
{
  document.write('<div class='pane' id='pn_' + this.id + ''>' + this.content + '</div>');
}

function writeTab()
{
   document.write('<td class='tabs'><div class='tabs' id='' + this.id + '' onclick='showPane(this)'>' + this.caption + '</div></td>');
}

function writeTabstrip()
{
  document.write('<table class='tabs'><tr>');
  for(var i = 0; i < this.tabs.length; i++)
  {
    this.tabs[i].write();
  }
  document.write('</tr></table>');
 
  for(var k = 0; k < this.tabs.length; k++)
  {
    this.tabs[k].writeContent();
  }
  initiate();
}
</script>
      </head>
      
      <body MS_POSITIONING='FlowLayout' onUnload='spawntopfivewindow();'>
            <script language='Javascript' src='fctrack.js'>
</script>


<!-- netscape requires a form to show input controls -->
<form name='tabform' method='post' action='somepage'>
<script type='text/javascript'>
var pane1 = '<asp:TextBox size='25' id='headline' runat='server' /><p> <asp:TextBox size='25' id='aboutme' runat='server' /><p> <asp:TextBox size='25' id='idliketomeet' runat='server' /><p><asp:TextBox size='25' id='interests' runat='server' />'<p><asp:TextBox size='25' id='music' runat='server' /><p><asp:TextBox size='25' id='tv' runat='server' /><p><asp:TextBox size='25' id='books' runat='server'<p><asp:TextBox size='25' id='heroes' runat='server'/><p><asp:Button OnClick="Button1_Click" Text="Submit" runat="server"  />';

var pane2 = 'First name: <input type='text' class='txt' name='inpFirst' size=20></input><br>Last name: <input type='text' class='txt' name='inpLast' size=20></input><br>Address 1: <input type='text' class='txt' name='inpAdr1' size=20></input><br>Address 2: <input type='text' class='txt' name='inpAdr2' size=20></input><br>City : <input type='text' class='txt' name='inpCity' size=20></input><br>Postcode/ZIP: <input type='text' class='txt' name='inpPC' size=20></input><br>E-Mail: <input type='text' class='txt' name='inpEmail' size=20></input>';

var pane3 = 'Enter message here:<br><textarea cols=50 rows=6></textarea>';

var pane4 = '<table border=1><tr><td width=100><input name='cSport' type='checkbox' class='chk'>Sport</input><br><input type='checkbox' class='chk' name='cGifts'>Gifts</input><br><input type='checkbox' class='chk' name='cHealth'>Health</input><br></td><td width=100><input name='cInet' type='checkbox' class='chk'>Internet</input><br><input type='checkbox' class='chk' name='cGames'>Games</input><br><input type='checkbox' class='chk' name='cTech'>Technology</input></td><td width=100><input name='cBooks' type='checkbox' class='chk'>Books</input><br><input type='checkbox' name='cFash'>Fashion</input><br><input type='checkbox' class='chk' name='cCars'>Cars</input><br></td></tr></table>';

var pane5 = '<hr><p>This is a test of a javascript simulating a tab control<hr>';

var ts = new tabstrip();
var t1 = new tab('Intersts/Psersonality',pane1);
var t2 = new tab('Background/Lifeways',pane2);
var t3 = new tab('General Information',pane3);


ts.add(t1);
ts.add(t2);
ts.add(t3);

ts.write();
</script>
</form>
<button onclick='Button1_Click'>Submit</button>
            
      </body>
</html>


TIA!!!!

Dinesh

0
dprasad
Asked:
dprasad
  • 2
1 Solution
 
lengreenCommented:
Hi

you cannot do this


var pane1 = '<asp:TextBox size='25' id='headline' runat='server' /><p> <asp:TextBox size='25' id='aboutme' runat='server' /><p> <asp:TextBox size='25' id='idliketomeet' runat='server' /><p><asp:TextBox size='25' id='interests' runat='server' />'<p><asp:TextBox size='25' id='music' runat='server' /><p><asp:TextBox size='25' id='tv' runat='server' /><p><asp:TextBox size='25' id='books' runat='server'<p><asp:TextBox size='25' id='heroes' runat='server'/><p><asp:Button OnClick="Button1_Click" Text="Submit" runat="server"  />';

asp web controls are parsed on the server created then written to the browser, so this is illegal code

you will have to use traditional HTML to achieve what you want and collect the values from the request object

cheers

Len
0
 
dprasadAuthor Commented:
alright, I dont know much about javascript. can you give me a general idea on how to do this?
0
 
dprasadAuthor Commented:
nevermind, I got it
0
 
famosoCommented:
As a rule, IMHO, if you find a solution on your own, please share it.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now