Stop AutoPostBack

P

Peter

ASP.NET 2.0
Visual Studio 2008

I have the following code and when the textbox displays and I press Enter
while in the text box I get AutoPostBack, how do I stop AutoPostBack?

TextBox txt = new TextBox();
txt.MaxLength = parm.MaxLength;
txt.ID = parm.ParameterNameID;
txt.Text = "12345";
txt.EnableViewState = true;
txt.AutoPostBack = false;
this.PlaceHolder1.Controls.Add(txt);



Thank You


Peter
 
P

Peter

ASP.NET 2.0
Visual Studio 2008

I have the following code and when the textbox displays and I press Enter
while in the text box I get AutoPostBack, how do I stop AutoPostBack?

If I add another textbox (not in the PlaceHoder) the AutoPostback does get
disabled in the txt control, but if there are no other text boxes on the
form the txt control allways does the AutoPostback


TextBox txt = new TextBox();
txt.MaxLength = parm.MaxLength;
txt.ID = parm.ParameterNameID;
txt.Text = "12345";
txt.EnableViewState = true;
txt.AutoPostBack = false;
this.PlaceHolder1.Controls.Add(txt);
 
P

Peter

I have tried the Convenience #1 Item #3 from the
http://marss.co.ua/UnexpectedPostback.aspx but the page still gets submitted
when I press the enter key and the focus is in the text box. Regardless how
many Textboxes or Input fields I have on the webpage, pressing Enter key
submits the page.

The only time I can get it to work is if I use UseSubmitBehavior="False",
but then FCKEditor control does not post it's value, so I can not use that.

Any other suggestions I can try?


Hi Peter,

This behaviour is not caused by value of AutoPostBack property of a
TextBox, it is default browser's reaction to pressing Enter key.
I posted some thoughts on this topic here:
http://marss.co.ua/UnexpectedPostback.aspx
Maybe you'll find it useful.

Regards,
Mykola
http://marss.co.ua
 
M

marss

I have tried the Convenience #1 Item #3 from thehttp://marss.co.ua/UnexpectedPostback.aspxbut the page still gets submitted
when I press the enter key and the focus is in the text box. Regardless how
many Textboxes or Input fields I have on the webpage, pressing Enter key
submits the page.

The only time I can get it to work is if I use UseSubmitBehavior="False",
but then FCKEditor control does not post it's value, so I can not use that.

Two different situations are described there, and the attempt to solve
situation #2 by one of the solutions for situation #1 is not very good
idea.

As I see you can avoid the postback if you set
btnSubmit.UseSubmitBehavior="False", where btnSubmit is a button which
submits the form to the server.
Concerning output HTML it is replacement of <input type='submit'> by
<input type='button'>. If you want <input type='button'> also submits
the form
you have to add a handler for onclick event:

btnSubmit.Attributes["onclick"] = "document.forms[0].submit();"

Try, maybe it will help. That is all that I can suggest, I do not
familiar with FCKEditor and can't give more concrete advice.

Mykola
http://marss.co.ua
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top