Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Need help with C# code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Durango2008 - 11 Mar 2008 18:16 GMT
Hi, I have a form which contains a table(Table1), within that table I have
label with an ID set to "1A".
Using something like:

if(Table1.FindControl("1B") != null)
{
   labelID = "1C";
}
else if(Table1.FindControl("1A") != null)
{
   labelID = "1B";
}

Label lblType = new Label();
lblType.ID = labelID;

TableRow tr = new TableRow();

TableCell tc = new TableCell();

tc.HorizontalAlign = HorizontalAlign.Center;

tr.Controls.Add(tc);

tc.Controls.Add(typeLabel);

Table11.Controls.Add(tr);

So whenever this code runs if it finds the latest Label for example "1B" it
will add a new tr and cell with an updated label "1C" or if it finds "1A" it
will update with new label "1B".

It does work with the initial label that is set in the .aspx file however
when run it again it will not find the new label to reupdate things.

Anyone have any suggestions?

thank you for any advice.
pipo - 11 Mar 2008 18:34 GMT
What do you mean by 'run it again'??
When Postbacking...
the whole Page will be new, so make sure to add your newly created control
as well otherwise it will not exists.

> Hi, I have a form which contains a table(Table1), within that table I have
> label with an ID set to "1A".
[quoted text clipped - 34 lines]
>
> thank you for any advice.
Durango2008 - 12 Mar 2008 11:28 GMT
> What do you mean by 'run it again'??
> When Postbacking...
> the whole Page will be new, so make sure to add your newly created control
> as well otherwise it will not exists.

I do add the new control with the lines:
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.HorizontalAlign = HorizontalAlign.Center;
tr.Controls.Add(tc);
tc.Controls.Add(typeLabel);
Table11.Controls.Add(tr);

Did you mean something else?
pipo - 12 Mar 2008 17:28 GMT
What do you mean by 'run it again'??

>> What do you mean by 'run it again'??
>> When Postbacking...
[quoted text clipped - 10 lines]
>
> Did you mean something else?
Durango2008 - 12 Mar 2008 19:17 GMT
> What do you mean by 'run it again'??

I meant postback sorry for confusion.
pipo - 13 Mar 2008 16:30 GMT
When posted back the 'original' page will be build and displayed.
So when you recieve a postback make sure to make the control there as well.
The first time looks like it works because there you build the control in.
With the next postback that control isnot there anymore, create it and then
it will work.

Hope this helps.

Simple example:
2 buttons on a page.
By clicking Button1 a label is created.
Now click Button2.......label is disappeared, right?
So, re create the label in Page_Load when it is a postback and it is needed
(e.g. Button1 was clicked)
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}

protected void Button1_Click(object sender, EventArgs e)
{
Label lbl = new Label();
lbl.Text = "New control";
Controls.Add(lbl);
}
protected void Button2_Click(object sender, EventArgs e)
{}
}

>> What do you mean by 'run it again'??
>>
> I meant postback sorry for confusion.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.