Greetings, I have an ASP.Net form with some standard controls (DropDownLists and TextBoxes) that I need to be disabled or enabled based on the checked state of a checkbox control.
I currently have it working via the CheckChanged event on a postback.
Can I use Ajax to accomplish the same thing without Posting Back?
You can use Jquery or Javascript to Hide or disable the controls client side.
Related
I have a ASP.Net(C#) page. When a user selects a value in dropdownlist, some new controls will be visible to him.
I am able to that now, but the page has to reload every time and state has to be maintained between postbacks.
Is there any way to do the same without reloading of the page in a easiest way possible without using ajax control toolkit?
Additional info: the data for the dropdownlist is coming from the database, and some places it has to be all server side so i can't use javascript .
You can try this idea: http://msdn.microsoft.com/en-us/library/ms178208(v=vs.100).aspx. I have not try it before but it seems logical.
you should go through updatepanel. Put all the controls inside a updatepanel which you want to show on selectedindexchanged event of the dropdownlist and write code behind on selectedindexchanged event of the dropdownlist accordingly. Hope this will help you...
I'm using VS2008 to develop my ASP.NET web site, I know how to use AJAX and update panels to perform partial page refresh, but is there any way that I can do the reverse action? i.e. can I use update panels to prevent some controls from reloads? I have a control which I don't want to be reloaded in page reloads, it is located in my master page as it should be active in all pages, what are my options now?
thanks
Try using UpdateMode property of update panel to Conditional..
When UpdateMode set to Conditional, the UpdatePanel will be updated only on postback originated by controls inside the panel or from the triggers specified.
for more info:
http://codeclimber.net.nz/archive/2007/05/24/updatemode-default-value-for-the-updatepanel-is-always.aspx
http://ajax.net-tutorials.com/controls/updatepanel-control/
Regards.
I have a RadGrid with a custom edit form (FormTemplate). The grid is in an UpdatePanel for asynchronous postbacks, as changing the selection in drop down lists and checkboxes needs to enable or disable other controls on the form. (Updating the controls synchronously is not acceptable to the user.)
As part of the edit form, I have a FileUpload control, but this does not upload the files when in an update panel.
I have tried adding the Insert/Update button as a PostBackTrigger on the UpdatePanel, but this causes an error on page load, as the UpdatePanel cannot find the control (the edit form is not open on load).
Is there a way to add/remove the trigger at runtime when the form is opened/closed?
Or is it possible to have the FileUploads work with the async-postback?
Yes, you have problem with is as FileUpload is in the list of controls that are not compatible with update panel (for more info here). One workaround for you could be swfupload. Another option is to use this jQuery plugin http://www.plupload.com/example_all_runtimes.php as stated here
There is a demo on the Telerik site that shows how to upload the files.
By using a RadAjaxPanel, RadCodeBlock and RadScriptManager with RadUploads instead of FileUploads it is possible to detect on the client side whether files have been selected for upload.
If there are files to upload, the AJAX postback can be disabled during the upload.
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=upload&RadUrid=cde8a81e-0eb1-49ca-8c31-4dba37da90c4
I am having issues with validators not firing (No expected error messages showing) when using Page.Validate() from code behind. The validators are placed inside an Ajax updatepanel.
It seems there are downloadable Ajax versions of the validators. I am not sure if I need these or if VS 2008 SP1 has them already. When the form is posted through a button, the validators work but they don't when I do a Page.Validate() on demand.
Yes, validators do work inside an UpdatePanel, but you need to use at least SP1 of ASP.NET 2.0. If you use SP1, you do not need and should not use the "ajax version" of the validators.
More details on this subject are available here:
StackOverflow: ASP.NET Validators inside an UpdatePanel
I don't want to force an update. In certain situations, I want to validate some form elements when a user changes the value on some form element. When I user makes a change to say a radio button or a dropdownlist, an automatic postback happens. When the postback occurs, I want the validation controls to fire as if I hit the submit button.
These controls which cause a postback have 'causevalidation' turned on. Another test is in the event handler of the control which caused the postback, I have a Page.Validate().
The question is why a button postback fires the validation but not another control which caused a postback?
Maybe we can take it from the top. Can you answer these?
Are you using .NET 2.0 SP1 or greater?
Are your validator controls inside the UpdatePanel or outside?
Are you using your site with javascript disabled (very unlikely)?
Note that your validators MUST be inside an updated UpdatePanel for them to display the error messages. If they are not in an updated UpdatePanel, the validators cannot change their appearance on the browser.
Did you call Update on your updatepanel?
They were included in a update for .Net framework a while ago, so yes, you have them in VS2008 SP1. I've found a problem where the server side method for CustomValidators fires twice with no "evil" effect, but otherwise they work ok.
As for the specific problem you're having, maybe the validators aren't inside the updatepanel, or some other panel ends up being refreshed by whatever control posted instead of the one that you want? Or even some ValidationGroups are defined somewhere and only these end up being validated? It's very hard to say without seeing code.
But making sure your validators are shown is easy: MyUpdatePanel.Update() will force the refresh.
I ended up using a single custom validator and doing my own validations in code behind and setting the custom validator's error message. This way I had more flexibility and it worked.
Using Ajax, it feels like client side validation.
I am using a cross page postback for Page A to pass data to Page B.
The button that causes the postback has its postbackurl set but is disabled until the user selects a value from a DDL at which point the button is enable using javascript. However this prevents the cross page postback from occurring, Page A just postbacks to itself.
If the button is never disabled it works fine. Anyone know how to solve this?
It looks like when the button is disabled .Net doesn't bother adding the necessary bits to handle the cross page postback on the client, so they will be missing when the button is enable client-side.
I guess one solution would be to have the button enabled to start with (so that .Net adds the cross page postback controls) and then disable it using javascript as soon as the control loads on the client. But this sounds a bit clunky.