PostBack & <asp:TextBox> question

J

John Smith

I have my <asp:TextBox> inside one of DataGrid's columns. I haven't set
AutoPostBack=True. When I hit the ENTER button, my page "refreshes" (I
belive that PostBack was performed - however not sure). I don't want
anything to happen when ENTER is being pressed. The other option is that
button event might execute (button next to my asp:TextBox). How can I do
this?
 
J

Jared

It is probably the button event firing.

You could put this code in your Page_Load event to confirm a postback.

if(IsPostBack)
{
Response.Write("A PostBack Occured");
}
else
{
Response.Write("A PostBack Did Not Occur");
}
 
J

John Smith

You could put this code in your Page_Load event to confirm a postback.

Just did that. Yes, it was PostBack, but WHO causes this PostBack? It is not
a button, because button have its OnClick event and I have put my code
inside it and that code doesn't execute when I press ENTER in my
asp:TextBox.

What should I do? :(
 
J

Jared

John

How many buttons do you have on your page? Is the button part of a
template or a GridView Command Button?

Is the GridView_RowCommand event firing?

I can't be sure without seeing your code.

Regards

Jared
 
J

John Smith

How many buttons do you have on your page? Is the button part of a
template or a GridView Command Button?

One button, which is inside template together with TextBox.
Is the GridView_RowCommand event firing?

I don't know. I haven't overrided this event so far (will try that).
 
J

Jared

John

I am not an expert, but I believe that the Button Control will always
cause a post back, due to the way a browser renders and deals with HTML
.. You could try using a link button instead if it is pressing enter
that is causing the problem.

Also, if the post back is causing a problem due to some code in your
Page_Load event, you could try grouping that code within the;

if(!IsPostBack)
{
}

So it only fires the first time the page loads.

Other than this, I am not aware of a method to turn off the RowCommand
event when you have a button control in the Grid.

Sorry I can't be more help.

Jared
 

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