Displaying error message without postback? - c#

I got this an asp.net 3.5 page that and I have few tabs (telerik tabs control with pageview) and I have panel on the top of the page and inside that has a label control displaying error message if it's any.
At the moment, if I want to display this, at the end of the event clicked button for instance, I have to do a custom URL redirection class to itself passing error message and display the error. BUT the problem with this approach let say you are working on 4th tabs and you click save button inside this then you loose the state of series of control (what's is being choosed, selected, typed etc). The page refreshed and displayed at the first tab again.
I want to display the error and at the same time know the state is for every control on the 4th tabs and automatically goes to 4th tabs. BTW ... this validation is done through server level.
I am appreciated your feedback/suggestion.
Thanks

I see several approaches here:
Make an ajax call with data to validate and show error message basing on its result.
Recover your control state after post back, you will need to write some client logic that will analyze url for some parameter after "#", e.g. http://my-site.com/tabs.aspx#4. Your script will know that you need 4-th tab.
You can try to recover your control state on the server, but I don't know how it is possible with telerick tab control.

Related

C# asp.net Maintain tab index after asynchronous postback ontextchanged

Ok, so I've researched this to the end of the earth and can't seem to find a solution that works.
I have a C# application, which is basically a web form made up of radio button lists and text boxes in an update panel. The form has multiple 'sections', each of which the user submits when completed. Each control performs a postback. This is because if the user modifies a section after completing it, the 'section saved' label needs to disappear.
This all works well, except the postbacks lose the tab order of the controls. I have found code examples that save the last control that had focus, which works well for the radio button lists, but because the text boxes post back when a user tabs to the next control (not modifies the text), it doesn't select the next control. The user has to hit tab again and it jumps to the third text box, not the second because technically, the second text box is what had focus after the initial postback. I hope this makes sense.
Any ideas? I can post code if required.
I should probably also add that this page is within a frame of our community portal.

Chrome Breaks Form by Persisting Drop Down List Selection on Back Button

Page A has a dropdownlist of shipping methods.
User makes a selection and clicks next.
Page B allows them to change their shipping address, which changes their shipping methods.
User clicks back button.
Page A shows new shipping methods in drop down, but Chrome has added a blank option at the top and made it the selected option. This blank option DOES NOT EXIST in the view source.
Chrome is choosing to insert a phantom blank selection item when its persisted drop down list value no longer exists, rather than respecting the selected="selected" tagged option.
This causes .net event validation to fail whenever the user tries to interact with the form, because this blank selection isn't real. "Invalid postback or callback argument. Event validation is enabled"
I've tried form.reset() on page load, and turning autocomplete off on the form tag. Anyone have any ideas? Much appreciated.

Is there a way to NOT load a specific control in ASP.NET/C#?

I've a container (RadDockZone - Telerik), and inside it, a textbox field with an "Asp:RequiredFieldValidator", which makes it mandatory. Every time that I work with AJAX operations, the entire container is "reloaded", including the RequiredFieldValidator. This makes the ValidationSummary show the same error message twice, until the page is completely reloaded (I'm using RadAjaxManager to solve the AJAX operations).
So, how can I "don't reload" a specific control (in this case, the RequiredFieldValidator) using C#?
Regards!
If you place the following in page load if(page.Isvalid) the required field validator will be fired once after submitting that form. The message will not be displayed twice.
If you do not include the textbox (or its wrapping containers) in the list of controls updated by the ajax manager, the textbox and the respective required validator should not be updated on ajax requests and the error message should not be visualized.
You should use validation groups. This lets you group all of your validation controls into a group. Then put this same validation group on your submit button and those validation controls will only validate when that particular button is clicked.
Property is assigned on the validation control and button using the ValidationGroup property.
Thomasvdb's suggestion of setting CausesValidation to false also might be a good way to do it.

Different popups for different textbox edits, possible?

I have an issue with a popup in Asp.net using AJAX modalpoup extender. Is it possible to show one kind of popup when the user edits few textboxes and the other kind of popup for the remaining textboxes.
I guess it is possible with some javascript function. Could someone help me out?
Ex: Only when txtbox1's value is changed, it should show me popup1 when the save button is clicked. Or else popup2.
Thanks in advance!
This might be something that is limited by the fact that you're using ASP.net's modulapopup. Have you tried looking into jQuery?
For example, you could assign event handlers to the specific buttons/textboxes and have them trigger different events - which you would then handle accordingly, i.e. displaying different popups. Take a look at jQuery UI, specifically their Dialog demo.

C# UserControl Validation

I have a UserControl with a Tab Control containing three tabs. Within the tabs are multiple controls - Datetimepickers, textboxes, comboboxes.
There is also a Save button which when clicked, calls this.ValidateChildren(ValidationConstraints.Enabled) Now, I click save and a geniune validation error occurs. I correct the error and then click save again - valdiation errors occur on comboboxes on a different tab. If I navigate to this tab and click save, everything works fine. How can this be? I haven't changed any values in the comboboxes so how can the fail validation then pass validation?
The comboboxes are bound to a dataset with their selectedValue and Text set. I just don't understand what is happening here.
This behaviour also occurs for some textboxes too. The validation rule is that they have to be a decimal - the default value is zero, which is allowed. The same thing happens, they fail validation the first time - I make no changes, click save again and they pass validation.
EDIT:
The error is not a Framework error - the error is the one I provide during my validation routine. e.g Select a valid drop down option.
I stepped through the process and the sometimes the combobox values are the default values other times the selectedvalue is the default but the text is null. I don't see how this can happen if I'm not changing anything in the combobox.
If you need any further information please let me know
thanks
Barry
The following is a quote from MSDN:
"Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown."
So I'm guessing that if before you press save the first time, you make sure that you've clicked on each tab at least once, it'll work as expected, but if you don't look at all tabs before saving, it fails?
Have you checked that the default value is not null ?

Categories