Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > how to get the dynamical control's content from server side

Reply
Thread Tools

how to get the dynamical control's content from server side

 
 
haiwen
Guest
Posts: n/a
 
      10-23-2003
hello, everyone:

I need to programmatically generate web control on a page.
such as:
for(int i=0;i<4;i++)
{
Label l=new Label();
l.Text="name "+i;
TextBox t=new TextBox();
t.ID=i.ToString();
t.Text="txt "+i;
Label l2=new Label();
l2.Text="<br>";
PlaceHold1.Controls.Add(l);
PlaceHold1.Controls.Add(t);
PlaceHold1.Controls.Add(l2);
}
but I can not get the content of those TextBox on server
side. could anyone help?

haiwen

 
Reply With Quote
 
 
 
 
Jacob Yang [MSFT]
Guest
Posts: n/a
 
      10-24-2003
Hi HaiWen,

Based on my research and experience, we can use the FindControl method.
Please refer to the following code snippet.
...
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
TextBox myText = new TextBox ( );
myText.Text = "Welcome to ASP.NET";
myText.ID = "myText";
PlaceHolder1.Controls.Add ( myText );
myText.Attributes.Add("style",@"Z-INDEX: 103; LEFT: 16px; POSITION:
absolute; TOP: 128px");

}

...
}

private void Button2_Click(object sender, System.EventArgs e)
{
TextBox1.Text = ((TextBox)(PlaceHolder1.FindControl("myText"))).Te xt;
}
...

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! 每 www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
 
haiwen
Guest
Posts: n/a
 
      10-24-2003
hello,Jacob Yang :

Thanks so much for your help.

haiwen
>-----Original Message-----
>Hi HaiWen,
>
>Based on my research and experience, we can use the

FindControl method.
>Please refer to the following code snippet.
>...
> private void Page_Load(object sender,

System.EventArgs e)
> {
> // Put user code to initialize the

page here
> TextBox myText = new TextBox ( );
> myText.Text = "Welcome to ASP.NET";
> myText.ID = "myText";
> PlaceHolder1.Controls.Add (

myText );
> myText.Attributes.Add("style",@"Z-

INDEX: 103; LEFT: 16px; POSITION:
>absolute; TOP: 128px");
>
> }
>
>...
> }
>
> private void Button2_Click(object sender,

System.EventArgs e)
> {
> TextBox1.Text = ((TextBox)

(PlaceHolder1.FindControl("myText"))).Text;
> }
>...
>
>Does it answer your question? If I have misunderstood

your concern, please
>feel free to let me know.
>
>Best regards,
>
>Jacob Yang
>Microsoft Online Partner Support
>Get Secure! 每 www.microsoft.com/security
>This posting is provided "as is" with no warranties and

confers no rights.
>
>.
>

 
Reply With Quote
 
haiwen
Guest
Posts: n/a
 
      10-24-2003
Hello Jacob Yang :

one more question is if there several kinds of controls in
placehold, but I just want to get the text of textbox
control. I use:
foreach(Control b in PlaceHold1.Controls)
{
if(b.GetType()==Type.GetType("TextBox"))
{
s +="score: "+((TextBox)b).Text+"<br>";
}
}
but I get nothing, Could you tell me what is wrong with it?

Thanks a lot,

haiwen
>-----Original Message-----
>Hi HaiWen,
>
>Based on my research and experience, we can use the

FindControl method.
>Please refer to the following code snippet.
>...
> private void Page_Load(object sender,

System.EventArgs e)
> {
> // Put user code to initialize the

page here
> TextBox myText = new TextBox ( );
> myText.Text = "Welcome to ASP.NET";
> myText.ID = "myText";
> PlaceHolder1.Controls.Add (

myText );
> myText.Attributes.Add("style",@"Z-

INDEX: 103; LEFT: 16px; POSITION:
>absolute; TOP: 128px");
>
> }
>
>...
> }
>
> private void Button2_Click(object sender,

System.EventArgs e)
> {
> TextBox1.Text = ((TextBox)

(PlaceHolder1.FindControl("myText"))).Text;
> }
>...
>
>Does it answer your question? If I have misunderstood

your concern, please
>feel free to let me know.
>
>Best regards,
>
>Jacob Yang
>Microsoft Online Partner Support
>Get Secure! 每 www.microsoft.com/security
>This posting is provided "as is" with no warranties and

confers no rights.
>
>.
>

 
Reply With Quote
 
Jacob Yang [MSFT]
Guest
Posts: n/a
 
      10-25-2003
Hi Haiwen,

Please refer to the following code snippet based on the sample in my
previous post.

...
private void Button2_Click(object sender, System.EventArgs e)
{
//TextBox1.Text = ((TextBox)(PlaceHolder1.FindControl("myText"))).Te xt;
foreach(Control b in PlaceHolder1.Controls)
{
if(b.GetType().ToString() =="System.Web.UI.WebControls.TextBox")
{
TextBox1.Text = ((TextBox)(b)).Text;
}
}

}
...

Does it answer your question? If I have misunderstood your conern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! 每 www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
haiwen
Guest
Posts: n/a
 
      10-27-2003
Hello,Jacob Yang :

Thank you very much for your help. It solves my problem.

Best wishes,

haiwen
>-----Original Message-----
>Hi Haiwen,
>
>Please refer to the following code snippet based on the

sample in my
>previous post.
>
>...
> private void Button2_Click(object sender,

System.EventArgs e)
> {
> //TextBox1.Text = ((TextBox)

(PlaceHolder1.FindControl("myText"))).Text;
> foreach(Control b in

PlaceHolder1.Controls)
> {
> if(b.GetType().ToString()

=="System.Web.UI.WebControls.TextBox")
> {
> TextBox1.Text =

((TextBox)(b)).Text;
> }
> }
>
> }
>...
>
>Does it answer your question? If I have misunderstood

your conern, please
>feel free to let me know.
>
>Best regards,
>
>Jacob Yang
>Microsoft Online Partner Support
>Get Secure! 每 www.microsoft.com/security
>This posting is provided "as is" with no warranties and

confers no rights.
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Dynamical loading of html files and executing of its javascript content. mowsen@googlemail.com Javascript 9 06-03-2007 07:34 AM
how to print tables with dynamical content? benny ASP .Net 0 01-11-2007 08:15 PM
Click-Event by dynamical Button Liqun Xu ASP .Net 2 12-05-2003 02:29 PM
Dynamical update of the CLASSPATH MARTIN Herve \(EXT\) Java 4 11-06-2003 09:39 AM



Advertisments