How to get drop down list to validate during postback? - c#

Well, I found the problem I was facing with the post back earlier. Somehow it turns out that drop down list, is failing event validation in all the pages. It wasn't failing validation earlier, so no idea what happened.
Anyway, now I have some 400 pages where this thing is happening. So, adding some code in all of them is out of question. So, now I want to know what I can do to get the drop down list considered as valid during the postback? Adding update panel is out of question as I will have to do it on oh so many pages.
Edit:
More details:
I have an application created in .Net 1.1. I ran the upgrade wizard in VS to upgrade to VS2012. Since then, I am finding a lot of bugs when post back happens. I had two functions for handling click event for buttons. The javascript function (used for validation) is fired properly, but the asp function wasn't called at all.
So, last week, I set eventvalidation to false, and everything worked. After reading more about it, I realised that postback was failing validation check. I checked eventtarget attribute, but that was null. So, I kept looking further. After a lot of head scratching, I finally found the culprit of that postback failure.
In that application, we add items to the dropdown, based on database query results. So, it is modified on run time. The script modifying the control is added to "ClientScriptManager", but that doesn't work. So, right now, my code has some 400 forms with dozens of dropdownlist created in runtime.
I have to get these dropdownlist removed from postback validation, or somehow return true for the validation. And that's where lies the problem. I have no idea how to do this.
P.S. Do let me know, which piece of code I should add here, if needed.

Related

RadWindowManager, RegisterScriptControl, and multiple controls with same ID issues

We just upgraded our Telerik controls from 2012.3.1308.45 to 2014.1.1403.45. As a result, a page that previously worked, doesn't now.
The initial error is as follows:
Script control 'RadWindowManager1' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
There are a couple of postings on the Telerik site about this. The preferred solution seems to be to set the RegisterWithScriptManager attribute on the control to false.
Doing this, then, makes another error pop up. So, I'm not sure if I'm moving forward or not. The new error is:
Multiple controls with the same ID 'RadWindowManager1_alerttemplate' were found. FindControl requires that controls have unique IDs.
The page has a bunch of Response.Write(...) ASP .NET expressions in the form of: <%=MyControl.ControlID%>. Every one of these expressions causes this error.
At this point, I'm stumped.
There was another posting on the Telerik site that suggested adding a Location element to the web.config for the Telerik.Web.UI.WebResource.axd would solve this. I tried that and it didn't do any good.
I also tried to use the Microsoft ScriptManager rather than the Telerik RadScriptManager, and that doesn't do any good.
I checked my web.config for duplicate entries, and there are none. I don't know what else to do. I'd appreciate any assistance on this issue.
For what it's worth, I've made some progress or dug myself deeper into a hole. I don't know:
Working with the second error, the multiple control issue, I discovered that we had on our page, a couple of controls that I got rid of.
First, I removed:
<telerik:RadCodeBlock runat="server"></telerik:RadCodeBlock>
primarily, this block appeared empty as there was nothing inside of it. Don't know if it's needed or not, but I removed it.
Second, I removed this:
<telerik:RadAjaxPanel ID="gridPanel" runat="server" LoadingPanelID="gridLoadingPanel">
<telerik:RadAjaxLoadingPanel ID="gridLoadingPanel" runat="server" Transparency="5">
<asp:Image ID="Image1" runat="server" AlternateText="Loading..." BorderWidth="0px" ImageUrl="~/App_Themes/Default/Images/Administration/Loading.gif"></asp:Image>
</telerik:RadAjaxLoadingPanel>
which existed, but wasn't being used at all.
When I did that, I got another new and exciting error:
RegisterForEventValidation can only be called during Render();
Using Google, I found out that one solution is to do this:
Add EnableEventValidation="false" to the Page directive.
Override the VerifyRenderingInServerForm in the code behind with nothing in it.
Did that, and now an even more newer and exciting error occurs.
Script control 'nameOfControl' is not a registered script control.
Script controls must be registered using RegisterScriptControl()
before calling RegisterScriptDescriptors().
The control in question is a RadNumericTextBox displayed within a table.
So, either I'm going deeper and deeper into a rabbit hole here, or I'm slowly working through multiple errors. I have no idea which it is.
Searching for this last error isn't giving me anything concrete to work with, though. Any additional help would be appreciated.
Make sure you do not have ClientIDMode set to Static for Telerik controls.
Then, if you use AJAX, wrap server code blocks in a RadCodeBlock tag (some server code blocks)
take away AjaxControlToolkit if you have it, it outputs changed MS AJAX scripts.
Don't use Response.Write() and the like if you use partial postbacks
If neither helps, strip down the page piece by piece to find the problem (e.g., some customization you have in place).
For me it helped to set the RegisterWithScriptManager="true".

Preventing duplicate postback processing when refreshing with update panels

basically what I am trying to achieve is this (asp.net 4) :
If a user does a postback on an ImageButton or similar control it should cause a page Post, and go through the entire asp life cycle.
If this has just happened, and the user presses F5 or similar to refresh, it should ignore all events from the previous post and just do a regular Get.
If the user clicks Save multiple times it should register only 1 Post and not cause duplicates being created etc.
If there are update panels on the page, a Post should only update the panels data, whereas a Get(refresh) should reload the entire page.
I have had a look around and am currently using the Response.Redirect method (once processing is completed in a post it does a response redirect to the same page to replace the Post with a Get). This is unsatisfactory for a number of reasons
It causes unnecessary overhead doing two page Posts every save
I would like to have regions of the page in Update Panels, and at the moment if you change something and save it in one region, it reloads the entire page.
I found this similar SO question here which highlights a few methods, none of which looks like they will solve my needs. I also found this which is an interesting method, but I was wondering if anyone could tell me if it will solve all my above needs before I try implement it? Also, is the onsubmit event firing the only difference between a Post or a refresh mimicking a Post?
Regarding the 3rd bullet above, I have read about the jQuery .one() function, but I am looking for an application wide solution, as most of the app has been developed without this in mind.
Thanks in advance!

JavaScript generated web page issue

I have a problem with javascript generated web page. I have a web page on the internet that is generated by javascript. I am working on changing a web page using wpf web browser control. I have to make some changes to the web page by inserting jquery, and changing css and hiding some elements.
Here is the issue.
Application works ok most of the time, but sometimes, for reasons unknown, it does not change the css or hides the elements. I presume that it has something to do with the javascript that actually generates the page. My code is executed, but no changes are made, so I presume that the script cannot find the elements in the page because they do not exist in the page, at the time of the execution of my scripts. This is just an assumption.
I need help resolving this issue. I have tried delaying the execution of my scripts for n seconds, waiting for body.ready, document.ready and window.ready, but nothing helped. Also, I use wpf web browsers LoadCompleted event, but... From time to time, the script simply makes no effect on the page. Did somebody have this issue, does anyone have any idea how to solve it?
Thank you very much in advance...
When building single page apps, always use a framework like Backbone or Sammy.js together with Mustachejs (or Hogan.js) for templating.
Since we don't have any code to look at, if you're using jQuery, I suggest you check out .live() and .on() for attaching event handlers to elements you plan on loading into a div (making them clickable) etc.

BeautyTips - Refresh after postback

I'm using the BeautyTips jQuery plugin in a template column in my RadGrid to show additional information.
Everything is working well, but I have one issue: After the user applies some changes and clicks the update button (which causes a partial page update), the BeautyTips plugin still shows the outdated info.
I've put a breakpoint on the code that loads the info it uses, and it is not hit after initally loading them; so BeautyTips is caching that result somewhere.
Is anybody aware of a way I can force those to refresh?
OK; I figured this one out:
There's an option in BeautyTips called ajaxCache which will cache the results of ajax calls.
Setting this to false (the default is true) solved my problem.

Update Panel working very slow

I'm writing an app in which user can register. While registering the one may choose several options and according to these regiester fields are visible or not and are required or not.
I came up with an idea that all fields will be in in the updatePanel and when users changes registration options I would set visibility of these fields on the server side.
It works but incredibly slow and whats more on the FF I have the given error:
The state information is invalid for
this page and might be corrupted
3 checkboxes with other fields are in the updatePanel
Each field is in dl tag with runat="server>
I had to do it like that cause for "required" option I simply add css class to this dl (need in in javascript validation. If field should be visible I set visible="false" for given dl and then that field for example FirstName with title and so on isn visible after postback.
Am I doing something wrong ? Why does it take so long (~4 min on localhost) and in firefox it doesnt really work (when I use debug I think that process completes without errors on ff, I dont understand that at all :)
If update Panel is so weak what would be other option to change visibility and adding required class to all dls. Logic is quite complicated and has to make query to DB so simple javascript would be quite tricky.
Thanks for any hints,
Oh and I'm using ASP.Net and cant upgrade on this project.
Thanks for help,
bye
Without code to look at, here are general things which will make an UpdatePanel slow:
Large amount of form data (such as Viewstate) being posted. Uploaded data is often slower than downloading data (depending on connection type, such as a home connection where uploads can be 5x slower than downloads). Even though you can't see it, every form field on the page is posted back to the server (even if its not in the UpdatePanel).
I would suggest going through your request/response data in Firebug and making sure that your async requests are less than 5K and your responses are no more than 20K.
A slow process on the server which is running when the UpdatePanel is posted. How does your code perform when the UpdatePanel is removed?
JavaScript errors (yours and Microsoft's). Here is a link to a known bug and a fix that I have used myself: http://support.microsoft.com/?kbid=2000262
Massive DOM manipulation (doesn't sound like this is the case for you).
BTW, searching for the error message you reported gives many possible causes:
http://www.google.com/search?aq=f&sourceid=chrome&ie=UTF-8&q=The+state+information+is+invalid+for+this+page+and+might+be+corrupted
As always, minimize or remove dependencies on ViewState...it's the source of many problems and enables poor design decisions.
You need to set update Panel properties update mode to Conditional instead of Always. Limit the number of controls you put into one update panel
You might want to check, Page events etc. Research on page directive and property AutoEventWireup
Since performance is the issue you highlighted, you might want to check that as well. Update panel mode should be conditional.
Check the triggers as well
Try with these properties values inPage directive. This is always at the top of your page. Let other properties be there as they were before. Update panels should not be slow like you are reporting.
<%# Page ViewStateEncryptionMode="Never" EnableViewStateMac="false"
EnableEventValidation="false" %>
I would also like to add that if your database query that you mentioned is complex, is taking a very long time, then the problem lies not with aspx page or update panel, but with your database query. You will then need to profile your query and check how much time it's taking to execute. The way to go in that case would be to fine tune your query at database level.

Categories