asp.net use client validation without posting to server - c#

I have a very long form that is divided in sections. I want to take advantage of the built-in ASP.NET validation controls without posting back to the server until the form is submitted. To provide more context, let me explain my idea. The form is divided in sections and each section will have a "Next" button. When the "Next" button is clicked, the section is validated with the client-side code that ASP.NET includes. If the section is valid, a jquery method will hide the section and show the next one. When the user reaches the last section of the form, a "Submit" button will be available and this button will fire the event to post the form to the server.
Any help or idea will be much appreciated.
Thank you.

For this you can have n no of Panel and each Panel will have a Next button. For validation each Panel will contain a validation group...so u need to have n no of validation group.
So each Panel will have a validation setup. Now u can have jquery on each button to hide the Panel and move the user to the next Panel.
I hope this can fulfill your requirement.

Related

Browser Back Button issue in asp.net

I have registration form, suppose there are 5 fields, and all are required i.e. mandatory.
My problem is that when user login & fill 2 fields of that registration form & click browser back button, then I want to restrict user to same form & Show requiredField Validator messages of incomplete fields. So How can I fire Validation on browser back button & restrict user on same form.
You cannot affect browser behavior when the user clicks the Back button.
The correct solution is to check right after user have been login, if he has complete the registration entries on database, and if not you redirect him to fill that data.
From your comments, to alert them a solution is to capture the onbeforeunload and check there if they have fill out everything or not, show your message.
Simple example, you just need here to place your conditions.
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
You can't disable the back button (see the other answers and their comments).
What you can do is check on every page whether the user is logged in. If not, redirect him to your login page. This way the user can't access the site without logging in, which I guess is what your client is really after.

Reload a Web Page Using C#

I have a web page that prompts for user input via DropDownLists in some table cells. When a selection is made the selection replaces the DropDownList so that the action can only be performed once. In the case that a change needs to be made I want to be able to click a button that reloads the page from scratch. I have Googled and Googled but I have not managed to find a way to do this.
Any advice is appreciated.
Regards.
Put a link on the page with the text "Reload" and the url the url of the page. It's perfectly valid to have a page with a link to itself.
If you don't like the link idea, use a standard Button and in the click event, use Response.Redirect to redirect to the current page.
You can set an OnClick for your button that resets each DropDownList's SelectedIndex to 0 instead of reloading the page from scratch. Alternatively, you can set a Response.Redirect([the page's url]) into the OnClick as is suggested here.

AJAX / ASP.Net / C# : Show next content only after validation?

I currently have an ASP.Net Web Form that looks like this:
Each section of this web form is wrapped in its own div so that they could be shown or hidden by changing the CSS display: property to none. My intention is to show each section one at a time, starting with the first one. When the user clicks "Next" the currently visible section will be hidden and the next section will be displayed in its place.
Many of the fields have ASP.Net validation controls attached to them (the "Zip Code" validation error message is displayed in this image as an example).
These validation controls have the runat=server
The whole Web Form is being loaded into a parent div dynamically through AJAX. Each Next button is not of type submit (they are of <input type= "button">).
How can I ensure that all fields in a given section are validated before allowing the user to hit "Next" ?
I am pretty stuck on this so some assistance would be really appreciated!
One option is each DIV you can have Next button and also you can use one ValidationGroup for button and the controls need to be validated inside div. if you set validation group it will validated only same group controls before post back.
Or you can have one Next button and change validation group of that button by using client side script or code behind when click on next button.
changing validation group of button with javascript on client side

onclick of any link the web user control is loaded without post back

i have a aspx page and in which\
Add Edit Delete
ABC GRIDVIEW
DEF
GHI
on click of any side link let ABC , DEF etc the Gridview related to that is opened
the gridview is in the Web user control and i have to show the gridview in the Placeholder dynamically.
in this case the whole page is not post back only the page in which the grid view is showing is post back and show the result.
please help and suggest me that how is it possible
It seems you are using dynamically lodaed controls. For events to work, you have to recreate your control on everypostback(OnLoad), if not the event won't be fired.
http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic4
If I understand you correctly, you want to Submit the form in 'GRIDVIEW' by clicking on one of the links on the left?
You can trigger submit events through jQuery as follows:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").submit();
});
This will submit the form, but presumably, you'll want to post the form to different locations regarding on which link is clicked?
I would suggest:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").get(0).setAttribute('action', 'myCorrectActionValue'); //this works, similar commands tend to fail silently
$("#myForm").submit();
});

How do I insert text into a textbox after popping up another window to request information?

I have an asp.net web page written in C#.
Using some javascript I popup another .aspx page which has a few controls that are filled in and from which I create a small snippet of text.
When the user clicks OK on that dialog box I want to insert that piece of text into a textbox on the page that initial "popped up" the dialog/popup page.
I'm guessing that this will involve javascript which is not a strong point of mine.
How do I do this?
You will have to do something like:
parent.opener.document.getElemenyById('ParentTextBox').value = "New Text";
What you could do is create an ajax modal pop-up instead of a new window. The semantic and aesthetic value is greater not to mention the data-passing is much easier.
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

Categories

Resources