.Net AutoPostBack issue

L

LionsDome

Hello,

I am still a little new to the .net environment and trying to learn
some of its features and functions.


I have a page with creates some dynamic controls on page load once a
user has selected the number of dynamc controls to be created. It
could be anywhere from 1 - 10. This happens with no problem. The
problem I am having is trying to refer to those controls text
property. I have a button that is going to save the values into a
table. But each time I type something in a dynamic textbox or select
a
value from the dynamic dropdown, the page is reloaded and I lose the
selected and/or entered values.


Is there a way I can avoid the page to reload when I click the button
and force it under certain conditions? This I believe may be hard but
then do I have other options?


I would appreciate any help I can get on this.


Thanks in advance.


Anil
 
D

Duy Lam

LionsDome said:
Hello,

I am still a little new to the .net environment and trying to learn
some of its features and functions.


I have a page with creates some dynamic controls on page load once a
user has selected the number of dynamc controls to be created. It
could be anywhere from 1 - 10. This happens with no problem. The
problem I am having is trying to refer to those controls text
property. I have a button that is going to save the values into a
table. But each time I type something in a dynamic textbox or select
a
value from the dynamic dropdown, the page is reloaded and I lose the
selected and/or entered values.


Is there a way I can avoid the page to reload when I click the button
and force it under certain conditions? This I believe may be hard but
then do I have other options?


I would appreciate any help I can get on this.


Thanks in advance.


Anil

If you need create dynamic web control in web page, you should create
them in page's Init event. Because every control in web page is created
at this event, you can see more information at
http://msdn2.microsoft.com/en-us/library/ms972976.aspx

For example:

protected void Page_Init(object sender, EventArgs e)
{
Button btn = new Button();
Label lbl = new Label();
Literal text = new Literal();
text.Text = "<br />";
lbl.Text = "You not click";
btn.Text = "Click me";
btn.Click += delegate { lbl.Text = "Hi, you clicked"; };
this.Controls.Add(btn);
this.Controls.Add(text);
this.Controls.Add(lbl);
}


May be you should use PlaceHolder control to contain your dynamic controls.
 
L

LionsDome

If you need create dynamic web control in web page, you should create
them in page's Init event. Because every control in web page is created
at this event, you can see more information athttp://msdn2.microsoft.com/en-us/library/ms972976.aspx

For example:

protected void Page_Init(object sender, EventArgs e)
{
Button btn = new Button();
Label lbl = new Label();
Literal text = new Literal();
text.Text = "<br />";
lbl.Text = "You not click";
btn.Text = "Click me";
btn.Click += delegate { lbl.Text = "Hi, you clicked"; };
this.Controls.Add(btn);
this.Controls.Add(text);
this.Controls.Add(lbl);
}

May be you should use PlaceHolder control to contain your dynamic controls.


Hello Duy Lam,

Thanks for the response. I do have a place holder that contain my
dynamic controls. But I guess I am not yet clear on how it will help
my in trying to make a reference to my controls in there. I cannot use
the page init event because the dynamic controls will only be created
once user selects from the dropdown. Should I be trying to do this
another way? I rather not given the time and effort I have spend so
far on creating this. Can give you perhaps give me a syntax or
something that will allow me to refer to the dynamic controls in the
placeholder?

Thanks.

Anil
 
B

bhaskarreddy12

Hello,

I am still a little new to the .net environment and trying to learn
some of its features and functions.

I have a page with creates some dynamic controls on page load once a
user has selected the number of dynamc controls to be created. It
could be anywhere from 1 - 10. This happens with no problem. The
problem I am having is trying to refer to those controls text
property. I have a button that is going to save the values into a
table. But each time I type something in a dynamic textbox or select
a
value from the dynamic dropdown, the page is reloaded and I lose the
selected and/or entered values.

Is there a way I can avoid the page to reload when I click the button
and force it under certain conditions? This I believe may be hard but
then do I have other options?

I would appreciate any help I can get on this.

Thanks in advance.

Anil
hi
anil,this is vijay
when you want to mantain controls data , you need to set viewstate
property =enabled/true in .aspx file .
you can set in three lelevels
page level it will enabled for enter page
control level this is for single mor controls set view state property
to to enabled/true
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top