C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

How to avoid posting the page when Submit button is clicked?


Posted Date: 02 Nov 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: S. SureshMember Level: Gold    
Rating: 1 out of 5Points: 5



Introduction

In a typical ASP.NET web application page, when we click on the submit button on the page, the page will be posted to the server. We can inject code into the client side by which we can stop posting the page unless otherwsie our clien side validations are all succeeded.

Consider a case where we have button (asp.net control) with the id btnSubmit and we need to do some validations on click of the button btnSubmit. We can achieve it by the following steps.

Steps to do:
1. On the codebehind page of the aspx file (i.e. aspx.cs ) write the following code on page_load:

btnSubmit.Attributes.Add("onclick","return PostNow()");

This code will inject the client side code 'onclick="return PostNow()"' on the page. You can check it by diong view source when your page is loaded in the browser.


2. Add a client side function PostNow() in the HTML page of the aspx file. Let this function do all the validations and if all the validatiosn succeed then return true or return false. If this function returns false then the page will not be posted and if the function returns true then the page will be posted.

<script language="javascript">
function PostNow()
{
alert ('Do your validations here');
return false;
}
</script>


In the above code I'm returning true always. This part of code has to be customized to suit your requirements.


Do let me know if any of you need clarifications on this. Also do mail me to get the full code for the page.

Thanks,
S Suresh
9342509573



Responses

Author: Mohan Raju Datla    03 Nov 2004Member Level: Bronze   Points : 0
this is helped me allot


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: Caching in .Net
Previous Resource: Setting the User Control Properties at runtime
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use