C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






How To Avoid PostBack while using a Web Control


Posted Date: 29 Jul 2008    Resource Type: Errors and Solutions    Category: General
Author: Jophy PhilipMember Level: Bronze    
Rating: Points: 5



Here is a problem I faced during one of my projects. I had to show an alert on a button click,but it always postsback. To avoid such a thing there are two ways.

1.)Use Html Control instead of a Web Control to avoid postback.

It's better to use an html control since,web controls always do a postback.

2.)If you can't avoid using a webcontrol,then do the following in code behind...

   Button.Attributes.Add("onclick","alert('Are You Sure ??');return false;");


OR

You can do it in the design part :

 <asp:Button ID="Submit"   runat="server" Text="Submit" 
onclientclick="alert('Are You Sure??');return false;" />


You can do it either way...This will prevent postback....






Responses

Author: Deepak S    29 Jul 2008Member Level: Gold   Points : 1
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
good Code to understand
Thanks to you
Regards,
Deepak S


Author: Vidhya    29 Jul 2008Member Level: Gold   Points : 1
hi,

its very nice.
keep on sharing these type of sharing codes to us.

thanks®ards,
Vidhya


Author: Narayanan Sukumaran    30 Jul 2008Member Level: Gold   Points : 0
Hi Jophy Philip,

I think this will help us.

Thanks


Author: vilas fulzele    30 Jul 2008Member Level: Silver   Points : 1
Hi,

Very good code.
Thank you very much for sharing such a nice code with us.

With Regards,
vilas



Author: Prafulla S Shimpi    16 Sep 2008Member Level: Gold   Points : 1
Its nice info.

Some more addition to this.

Use javascript for alerts or validations if you wish to avoid postbacks and prefer to execute the script on client side instead of server side.

Hope this will help




Author: Kundan Kumar Sinha    16 Sep 2008Member Level: Gold   Points : 1
Hi,

Set the AutoPostBack property of that control to false.

Regards,
Kundan


Author: Deepak    29 Nov 2008Member Level: Silver   Points : 1
javascript alerts and validations are more flexible than server side javascript.


Author: karthika    02 Jan 2009Member Level: Bronze   Points : 1
hi friends.
In my project im using Ajax with Timer here i want to set alert message when time goes to 0:0:0.0 like tat.
plz any one help me.




Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Using HTML controls instead of web controls  .  PostBack  .  How to avoid postback events  .  Design Part  .  Confirm Messages  .  Code Behind  .  Avoiding Postback events  .  ASP.Net  .  Alert  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Cannot INSERT Data
Previous Resource: OleDbException - Operation must use an updateable query
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use