ImageButton problem with page refresh

G

Guest

Problem
I have a problem with web image button control click event. The click event does not get trigger until it has not been clicked once or page refresh occures(which is fine).

When click event fires first time it executes code associate with click event(As I expected). the problem is when you refresh page it fires a click event automatically.

I looked around many posts and did not find any topics about this problem. Infact the same behavior occured for regular web button control click event too.

Any ideas..


My test example

Let say you have webproject and page name is WebForm1

Drop one textbox control and one imagebox control on webpage form

Double click on Imagebox control.

It will create following event

private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
//some code
}

Set break point on private void ImageButton1_Click

Test1: Hit page refresh button on IE
Result: nothing will happen ( I mean private void ImageButton1_Click will not trigger)

Test2: type some text in textbox and click image button.
Result: private void ImageButton1_Click will trigger and it will stop at break point.
Hit Debug->Continue again

Test3: do not do any thing after Test2. Just hit page refresh button on IE
Result: private void ImageButton1_Click will trigger.

Why ? I want to have private void ImageButton1_Click occure only when Imagebutton click occurs not on page refresh.
 
B

bruce barker

this is by design. in the test 3 case, the browser knows the render was a
result of a form post. to refresh the page, it needs to resubmit the post
data (normally it alters you to this). to the server this looks no different
than the orignal post.

-- bruce (sqlwork.com)



ppatel said:
Problem:
I have a problem with web image button control click event. The click
event does not get trigger until it has not been clicked once or page
refresh occures(which is fine).
When click event fires first time it executes code associate with click
event(As I expected). the problem is when you refresh page it fires a click
event automatically.
I looked around many posts and did not find any topics about this problem.
Infact the same behavior occured for regular web button control click event
too.
Any ideas...



My test example:

Let say you have webproject and page name is WebForm1

Drop one textbox control and one imagebox control on webpage form

Double click on Imagebox control.

It will create following event

private void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
//some code
}

Set break point on private void ImageButton1_Click

Test1: Hit page refresh button on IE
Result: nothing will happen ( I mean private void ImageButton1_Click will not trigger)

Test2: type some text in textbox and click image button.
Result: private void ImageButton1_Click will trigger and it will stop at break point.
Hit Debug->Continue again

Test3: do not do any thing after Test2. Just hit page refresh button on IE
Result: private void ImageButton1_Click will trigger.

Why ? I want to have private void ImageButton1_Click occure only when
Imagebutton click occurs not on page refresh.
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top