Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

My issue is that button's click event occurs if the page is refreshed.

Can body help me out in solving this problem.

Thanks.
Posted
Comments
Hiren solanki 17-Jan-11 8:31am    
Can you please share your code snippet ? so that we can have clear idea.
Michael Waguih 17-Jan-11 8:45am    
Is this in web application ?

I am sure, this is simply not true.

You could not proof your event occurs. This could be not event but merely your event handler which could write as a separate method: you call it from somewhere else.

Do the following: 1) locate your event handler; 2) in Visual Studio, click context menu on its name, select and click "Find All References"; If you cannot do it, perform full text search.

It will find you the reason of effect you see. Did you find it already?
 
Share this answer
 
Comments
Espen Harlinn 17-Jan-11 9:07am    
5+ decidedly helpful
Thanks for the reply.

Yes it is web application.

And code is some what like following

protected void Page_Load(object sender, EventArgs e)
{
// basic action to be performed on page
}

protected void btnUpload_Click(object sender, EventArgs e)
{
//Code inside this is for uploading file.
}

Now whenever I refresh my page, btnUpload_Click is called by default and it creates a copy of file.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Jan-11 9:24am    
Do what I say in my answer, this time with these two handler. Also, in your question you mentioned button click, now you're showing something irrelevant. Why?

Why you show handlers without showing where the events are set. Show the statements with "+="!
Looks like you are unable to express yourself clearly. It looks like once you use upload button and then whenever you press F5 (do a refresh), same event triggers again (A common issue).
If so, have a look at this artilcle for workaround: Refresh Page Issue in ASP.Net[^]
 
Share this answer
 
Though this is an old post, i am answering to this, so that others can get help.
The problem occurs due to postback as sandeep mewara hinted earlier.

how-to-avoid-the-button-events-on-refresh-of-page[^]

My easy way out is using an Update panel[^] and placing the controls within it.When the page is refreshed the postback event will have no effect on controls within it.


Note: Update Panel is available only in versions after VS2008.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900