Simple question!

D

Dom

<%# Session("oID") = Container.DataItem("VendorID")%>

The above statment, writes the value of the 'VendorID' instead of assigning
it to the session variable.

What's wrong? I'm a classic ASP developer and have been asked to help with a
quick fix for a .net site. Tried googling for help but found nothing useful.

Thanks
 
R

Richard Kure

in VB.NET, the advantage is that you seperate the code from the HTML, so in
your ".vb" file, you would write something like this

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Session("oID") = Container.DataItem("VendorId")

End Sub

'or

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Session("oID") = Container.DataItem("VendorId")

End Sub


hope this helps,
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

You are mistaken in your analysius of what is happening. The value is
written to the page, but not instead of the assignment. Both are taking
place.

You are putting the vendor id in the session variable, then you write
the value of the statement to the page. The value of an assignment
statement is the value that is assigned.

What your code is doing is similar to:

<% Response.Write( Session("oID") = Container.DataItem("VendorID") ); %>

You can put the assignment in a tag that doesn't produce any output:

<% Session("oID") = Container.DataItem("VendorID"); %>

Or even better, put the statement in the code behind of the page
instead. There is really no reason to have the statement in the page, as
it doesn't produce any output.
 
D

Dom

Thanks for the help. Am I correct in thinking if I put it in the code behind
page I will have to recompile the dll?
 
D

Dom

I've tried

<%# Session("oID") = Container.DataItem("VendorID")%>
<%Response.Write("ID : " & Session("oID"))%>

and the Session variable is still empty

The suggested code

<% Session("oID") = Container.DataItem("VendorID"); %>

or

<% Session("oID") = Container.DataItem("VendorID") %>

generates the error : Name 'Container' is not declared
 
D

Dom

Still having no luck with this. I'm unable to change the code behind page
and recompile so my only option is to put the vb code into the aspx page.

<%# Session("oID") = Container.DataItem("VendorID")%> outputs 'False'

and

<%# Container.DataItem("VendorID")%> outputs the vendor id (i.e. 516)

Can anyone help!
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Oh, so you are using VB? As you said that the code wrote out the vendow
id, I assumed that you were using C#. In VB it would write out the
string representation of a boolean instead.

In VB the code is not an assignment at all, but an expression. You are
comparing the two values and writing out the result. That of course does
not change the session variable.

Data bindind tags are used to output values, not executing code. You
should get the data directly from the data source instead of getting it
through a databound container.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top