Wednesday, March 28, 2012

Strange bug with textbox.text property

I have this is my page_load

txtSearchTerm.text = "All"

Then I have an imagebutton, when its clicked I want to redirect to a page based on the value of that textbox.

So in my imagebutton click event I have

Response.Redirect("auctions.aspx?search=" + txtSearchTerm.text)

My problem is this text is always "All", even when the user changes the value of the textbox

????

Help !

put you initialize in !IsPostBack

if(!IsPostBack){this.txtSearchTerm.Text="ALL";}

or you can set the default value in the form .aspx file use Text="ALL"


hi,

zeroxp kind of touch it a little, but i want to add something to his reply.

whenever a client click on a button on your webform, asp.net actually will reload itself, then process the Button1_Click event. Therefore, if you want to do something when the page is load, but not everytime it refrashes, use if (!IsPostBack){} or in vb.net: if page.ispostback = false then .

Just want to remind all people out there who maybe thinking this is a bug.. no it isn't... just the way asp.net webform was designed.

Alan,

0 comments:

Post a Comment