.Net AutoPostBack issue
am 16.11.2007 21:40:44 von 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
Re: .Net AutoPostBack issue
am 17.11.2007 16:42:40 von Duy Lam
LionsDome wrote:
> 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 = "
";
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.
--
Duy Lam Phuong
Re: .Net AutoPostBack issue
am 20.11.2007 16:57:04 von LionsDome
On Nov 17, 10:42 am, Duy Lam wrote:
> LionsDome wrote:
> > Hello,
>
> > I am still a little new to the .netenvironment 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 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 = "
";
> 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.
>
> --
> Duy Lam Phuong- Hide quoted text -
>
> - Show quoted text -
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
Re: .Net AutoPostBack issue
am 20.11.2007 18:07:36 von bhaskarreddy12
On Nov 17, 1:40 am, LionsDome wrote:
> 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