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

November 17th, 2010, 08:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

November 17th, 2010, 10:37 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
so if you want to write something from the sql you use the "repetar"?
|
|

November 17th, 2010, 10:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

November 17th, 2010, 11:04 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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..
|
|

November 17th, 2010, 12:38 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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"
|
|

November 17th, 2010, 12:47 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

November 17th, 2010, 12:55 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
thanks alot
|
|

November 17th, 2010, 01:48 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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 
|
|

November 17th, 2010, 01:55 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

November 17th, 2010, 03:20 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 55
Thanks: 9
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |