Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing variables in page from code behind pages 2

Status
Not open for further replies.

NerdTop72

Programmer
Mar 14, 2005
117
US
I have SQL data and I know how to pull it in from my code behind pages in VB. I am just a little confused how to stick it in my page for viewing. I was adding lots of labels on my page and writing data that way but the page load was soo slow. now i want to write some extra html data too from SQL. I would like to hear what other methods you use to write things in the pages.

-Thanks
Jason
 
Have you looked at the toolbox in VS and see what controls you can use?
How about a repeater, Datalist, gridview, treeview, literals..etc.
 
this is web development 101. if you can pull data, you can push data as well.

if you have experience with web develop from other languages then webforms will feel foreign (postback, viewstate, "stateful" web environment). MS MVC or Castle Monorail may be a better choice.

If you are new to web development then webforms will not seem so weird (but there is not other web development environment like it).

factors that effect throughput:
1. efficiency of the query
2. amount of data queried
3. amount of data displayed on screen
4. network speed/hardware specs

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
I was looking more to pass variables in the page instead of using a control. I'm not sure how to send information from my aspx.vb pages to the asp page like this. I want to use HTML tags and CSS in my SQL database. The last time I used labels as my control to fill in RSS feed information. When I tried to insert HTML in a label it would display the HTML information not in HTML format. I want to create something similar to wordpress, a back end database to fill in content on the main page? BTW I am only knowledgeable with data entry screens for work purposes with asp.net. not at all familiar with Rails or PHP. My thinking is since I have asp.net experience to make my own back end tool to create a good web 2.0 experience. If you think asp is not a good environment to work in, or know of a better one, I am all ears.

Thanks,
Jason
 
A lable will take the HTML and render it as it should, not as a literal string.

If you want to use css from a db then you just have to create server side tags on your controls, and referecne them from the code-behind.

ex: <tr id="mytr" runat="server">

codebehind:
mytr.attributes.add("class","YourCSSClassNameHere")

 
asp.net != webforms. asp.net only services requests with a response. webforms is an html engine.

the idea/reason of webforms is to create an html engine that behaves like the windows desktop environment (statefullness, events, life cycle). It allows desktop devs to work in the web environment without understanding the web environment.

If you think asp is not a good environment to work in, or know of a better one, I am all ears.
opinions vary. personally I cannot stand webforms. I favor Monorail (no need to switch to MS MVC yet).

The last time I used labels as my control to fill in RSS feed information. When I tried to insert HTML in a label it would display the HTML information not in HTML format.
you are using an html for to render non-html data. (RSS is XML, not HTML). this would be better suited for a custom HttpHandler (IHttpHandler) where you define the output using HttpContext.Resonse.Write("...");

that said, you can send raw html via a webforms Page with a literal control. However this sort of defeats the purpose of webforms.

I consider this code a problem
Code:
mytr.attributes.add("class","YourCSSClassNameHere")
define the classes in the html, not the server code. You can dynamically load the CSS files to define what the class means, if necessary. (google for more information)

all the code behind should do is pass data to the html markup. nothing more, nothing less.

want to create something similar to wordpress
why reinvent the wheel? there are numerous blog engines already available.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 

I was looking for this HttpContext.Resonse.Write("...") I didn't know where to start searching for what I wanted online. I'm glad you guys are here and understand my week skills with English & Grammar.

Using the response.write command, how do I leave a variable in the asp page and parse the information to where i want it to go? For instance. I have a page load that reads my database, finds something like "<center>Hello World</center>" and puts it in a column on the page. how do I get the page load to take that information from the database and put it on the asp page in the column i want. I hope this makes sense because that is what i am having problems with. I don't know what to search for.

Earlier I meant I tried RSS and HTML individualy in my labels. I created an array of labels and displayed RSS content. But I wanted to try to insert other information from a database like "<center>Hello World</center>" and have it respond as HTML. didn't work that way. The ASP.net that I am working on is just a simple interface to my database back to hold information for different areas on a front end page. My Idea for database structure is a bit more complex then what a simple blog engine can do. Not to mention creating one from scratch can have all the options I want to implement. I've done my research on several pre designed packages and most are costly or are too simple.

Thanks again,
Jason
 
I consider this code a problem
Code:
mytr.attributes.add("class","YourCSSClassNameHere")
define the classes in the html, not the server code. You can dynamically load the CSS files to define what the class means, if necessary. (google for more information)
The code will render the same HTML as if you placed the HTML directly in the .aspx, there is no difference. Since the post is confusing, I assumed he was talking about assigning things on the page dynamically.

But I wanted to try to insert other information from a database like "<center>Hello World</center>" and have it respond as HTML. didn't work that way.

That is becaue <center> is not a valid html tag.
 
The code will render the same HTML as if you placed the HTML directly in the .aspx, there is no difference. Since the post is confusing, I assumed he was talking about assigning things on the page dynamically.
yes, the end result is the same. It comes down to separation of concerns and who/what should be responsible for rendering the html.

@NerdTop72,
I think one issue you are having is how much html you store in the database. snippets make sense for things like blog posts, comments, etc. must I would try to keep as much html out of the database as possible. Also mixing webforms with raw html is somewhat counter intuitive to using webforms (my exprience).

webforms has the concept of a page lifecycle. you cannot easily plug a Response.Write() into the codebehind and expect the html to render where you want it. there are ways of doing this but webforms actually makes it harder to write custom html that not.

depending on what you actually want to render. CSS may be a better option than trying to store html in the database.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top