niros Posted June 25, 2004 Posted June 25, 2004 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. Quote
Arch4ngel Posted June 25, 2004 Posted June 25, 2004 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". Quote "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
PWNettle Posted June 26, 2004 Posted June 26, 2004 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 Quote
niros Posted June 26, 2004 Author Posted June 26, 2004 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!! Quote
Moderators Robby Posted June 26, 2004 Moderators Posted June 26, 2004 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 <% %>. Quote Visit...Bassic Software
niros Posted June 26, 2004 Author Posted June 26, 2004 I didn't know that, its greate new actually. do you know where can I find tutorial for that? thanks. Quote
niros Posted June 26, 2004 Author Posted June 26, 2004 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. Quote
Moderators Robby Posted June 27, 2004 Moderators Posted June 27, 2004 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")%> Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.