ASP to .NET

niros

Newcomer
Joined
May 25, 2004
Messages
23
I am new with .net, and I have the following question:
I created a public variable 'total' in the code page of the aspx page.
I want to call this response.write this variable content with out setting a runat=server component I just want to do <%=total%>
it doesn't work when I do that.

how can I integrate between variables that I decalre in the aspx code page to the aspx html page?

Thanks.
 
Well.. what's new with ASP.NET is called CodeBehind. When you have your server-side control... just select and event (a lightning in the propertie window) and double click to where is name will be and your event will be created.

Right... now... in the C# or VB.NET function all you have to do is :
MyServerSideControl.Text = total

Isn't it easy ?

Doing thing in the HTML page is called ASP way... while CodeBehind is really specific to ASP.NET. I recommend using the CodeBehind and getting yourself in OOP. Unless needed... I don't recommend using the "ASP way".
 
Arch4ngel said:
Doing thing in the HTML page is called ASP way... while CodeBehind is really specific to ASP.NET. I recommend using the CodeBehind and getting yourself in OOP. Unless needed... I don't recommend using the "ASP way".

I fully agree. The "asp way" is over. I prefer, and it's that standard where I work, to do all ASP.Net code in codebehind. We have a few instances of server-side blocks in the .aspx, mostly due to the fact that some of our devs were reluctant to drop the "classic asp style" of creating impossible to read or maintain pages from hell until we beat them up with coding standards - and because of the fact that when we first adopted .Net the team had some harsh deadlines and they sometimes had to sacrifice learning how to do things right for making things work. Me and other codebehind crusaders cringe every time we see <%%> in an .aspx and replace that junk as we can!

Paul
 
Ok,
so actually every thing can be done with code behind.
so that’s rise another questions, can you make datagrid, repeater with code behind without the <%%>?

but to the original one, what I am trying to do now is to use 'total' which is the total number of pages to be displayed. now wouldn't it be more efficient to just put it in the correct place and use <%%> instead of created a server side for it??

Thanks!!
 
Although I agree with Paul and Arch's comments, I think Niros is using DataBinding in a DataGrid, something like this....
Text='<%# DataBinder.Eval(Container, "DataItem.someField") %>'

When you bind the control at design time, allowing the columns to be generated automaticaly you end up with the above code, however you can create your own dataTable or dataSet and not need to use <% %>.
 
I didn't know that, its greate new actually.
do you know where can I find tutorial for that?
thanks.
 
BTW,
I still wasn't able to use the public variable 'total' in the aspx asp code.
If I do want to take the code behind pre declared variable how can I use it in the asp side page?
thanks.
 
Let's say you have a function in the code-behind that does something like this...

Public function GetMyMessage(byval str as string)as string
if str = "hello" then
return str & " world"
else
return "you didn't say hello"
end if
end function

Then in your aspx code...

<%#GetMyMessage("hello")%>
 
Back
Top