Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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".

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
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

Posted

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!!

  • Moderators
Posted

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 <% %>.

Visit...Bassic Software
Posted

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.

  • Moderators
Posted

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")%>

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...