Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 17th, 2010, 08:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
i can play more and write better program
I might agree with the first part, but certainly not with the second part of that.

Response.Write in ASP.NET works different than it did in classic ASP. It fires quite late in the life-cycle of a page when used in the markup, and may write to unexpected locations when used in the Code Behind.

I haven't had the need to use Response.Write in ASP.NET for years. Your milleage may vary of course, but it's something to be aware off. Personally, I don't think that using it leads to better or more maintainable applications in the long run. Just my 2 cents....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 17th, 2010, 10:37 AM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

so if you want to write something from the sql you use the "repetar"?
 
Old November 17th, 2010, 10:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It all depends on the requirements. You could use a Repeater, a DataList, a GridView, a ListView or any of the other data controls if they suit your needs.

Alternatively, you could loop over your data in code and create new elements on the fly. For example:

Code:
 
Literal literal = new Literal()
literal.Text = someDataFromADatabase;
placeholder1.Controls.Add(literal);
This code creates a new Literal control, populates its Text property and adds the control to a PlaceHolder (which should be defined in the markup or elsewhere in code).

What's your scenario exactly? Any reason why you can't use the data-bound controls?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 17th, 2010, 11:04 AM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

it be more difficult ,i mean that if i want to post any comment its hard when i try that if pepole press the subject then the body message will open to.
or post a advertisement every 10 post.

Quote:
Literal literal = new Literal()
literal.Text = someDataFromADatabase;
placeholder1.Controls.Add(literal);
i will try it

Last edited by nir987; November 17th, 2010 at 11:13 AM..
 
Old November 17th, 2010, 12:38 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

its not so good,i can only write PlaceHolder1.Controls.Add(lerr)once.
if i try to write it twice is still write it once.
PlaceHolder1.Controls.Add(lerr)
PlaceHolder1.Controls.Add(lerr)
(ler.text="hi")

i got only one hi
"hi"
i want to get "hihi"
 
Old November 17th, 2010, 12:47 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
,i mean that if i want to post any comment its hard when i try that if pepole press the subject then the body message will open to.or post a advertisement every 10 post.
It might be the beer I am drinking, but this makes absolutely no sense to me....

Quote:
PlaceHolder1.Controls.Add(lerr)
PlaceHolder1.Controls.Add(lerr)
(ler.text="hi")

i got only one hi
It's because it's the same control. Since it's a reference, it doesn't get duplicated. Either assign hihi to the first Literal, or new up a new one:

Code:
 
Literal literal = new Literal()
literal.Text = "hi";
placeholder1.Controls.Add(literal);
literal = new Literal()
literal.Text = "hi";
placeholder1.Controls.Add(literal);
Now you'll get hihi

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
nir987 (November 17th, 2010)
 
Old November 17th, 2010, 12:55 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

thanks alot
 
Old November 17th, 2010, 01:48 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

tell me how do i call button.onclick
if i use that way?

like

Dim btn As New Button
PlaceHolder1.Controls.Add(btn)

how do i write a click code? its rellay important
 
Old November 17th, 2010, 01:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
its rellay important
Not only that; it's quite complex as well.

You need to dynamically create the control in the Init phase and then hook up its Click event to a method. The control is then recreated after a postback and the Click will work.

This may be a good place to start to learn more about this: http://www.singingeels.com/Articles/...in_ASPNET.aspx

Also, Google knows more: http://www.google.com/#hl=en&q=dynam...ai=&fp=1&cad=b

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 17th, 2010, 03:20 PM
Authorized User
 
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
Default

i understand that,but im still dont see button.click
i dont have the options.
i have button.CommandArgument or onclintclick ,but i need button.click.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to put a button control in a GridView control ryan.webb ASP.NET 2.0 Basics 2 December 28th, 2007 05:26 AM
HTML Button in Asp.Net vallabh53 .NET Framework 1.x 0 October 17th, 2007 01:01 AM
html button k.manisha ASP.NET 1.0 and 1.1 Professional 0 April 26th, 2007 03:31 AM
make html button default sansircar ASP.NET 1.0 and 1.1 Professional 1 October 23rd, 2006 04:25 PM
put part of html in string DOM Dj Kat Javascript How-To 3 February 22nd, 2006 04:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.