Adding articles ASP.NET/C#


Author Message
some_911@hotmail.com

Posted: 2/17/2011
Quote message 

working in vs 2010 using asp.net and c#

I realized realised the databinding trick to read controls from aspx however what if i wanted to add controls to the article from cs??

i did


Article1.DataBind();
Button y = new Button();
y.Text = " button";
y.ID = "yid";
Article1.Controls.Add(y);


but this adds the button after the article ( i think it adds after contentTemplate)
i even tried creating new article and adding controls then adding the article but that didnt work also.
any input is appreciated
thanks
 
Axar

Posted: 2/17/2011
Quote message 

Okay so I did lot of playing around with code and used code by Stephen Anderson
here:
http://www.artisteer.com/Default.aspx?post_id=136690&p=forum_post


Im fairly new with asp.net but what I wanted to do was add as many articles i want and also be able to change their text from CS when ever i wanted.

Since i never figured out how to add text (html) in the article from CS but i did figure out how to add articles using Article newarticle = new Article() and then adding that to the SheetContentPlaceHolder controller

to sum it all up this is what i did to add 10 articles and change the 2nd articles text once they all were displayed


x = (ContentPlaceHolder)Master.FindControl("SheetContentPlaceHolder");
if (!IsPostBack) {
for (int i = 0; i < 10; i++) {
Literal a1 = new Literal();
Literal a2 = new Literal();
Literal a3 = new Literal();
a2.Text = BlocksAndArticles.ArticleEnd();
a1.Text = BlocksAndArticles.ArticleStart("Welcome" + i);
a3.Text = "<p>THIS IS MY TEXT first " + i + " <p>";
a1.ID = "Article"+i+"Start";
a2.ID = "Article"+i+"End";
a3.ID = "Ariticle"+i+"Text";
x.Controls.Add(a1);
x.Controls.Add(a3);
x.Controls.Add(a2);
}
}
Literal lol = (Literal)Master.FindControl("SheetContentPlaceHolder").FindControl("Ariticle1Text");
lol.Text = "<p>NOOOOOOOB</p>";



i apologize for the varibles and text it was just a test lol
anyway
if anyone has any ides to make my life easier ? something mybe im missing? thanks
Axar