I am using ASP.NET ajax to dynamically add/remove controls from a page without using full postbacks. The UI is very complicated. Under certain scenarios, when a control on the page causes a full postback, after changing the controls via async postbacks, I get this error:
Invalid postback or callback argument. Event validation is enabled using '<pages enableEventValidation="true"/>'
I can fix it by setting EnableEventValidation="false" at the page level.
What are the implications of doing this? Are there times when it is ok to do this or is this a hack?
If you have a WYSIWYG input text box or a textbox expecting HTML, then you have to disable validation or do some JavaScript hack.
The catch is that you will need to provide thorough validation to prevent XSS and such.
I would definitely say that it is a hack.
As far as reducing code complexity, have you tried inheriting from some of the controls and putting a lot of your code behind them? This definitely sounds like a case for refactoring!
It specifically says on their database tutorial that, currently you have to disable EventValidation. It is a bug.
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/CCDWithDB.aspx
It may not directly answer your question, or seem relevant...
However, if your UI is very complicated, there's probably something wrong with it. Following KISS is a good idea for obvious reasons.
If your UI is complicated, then the chances are you don't understand it, so you'll get more problems, alot of which you may never notice. Your problems and bugs won't be easy to trace or figure out, and are likely to be obscure and removed from the actual cause of the problem.
Secondly, if it's complicated for you, and you wrote it, it's probably incomprehensible for anyone using it. Even if you're just meaning managing the code, the complexity is probably reflected in the presentation.
I suggest you take a look at redesigning the UI so that it isn't so complicated. It will always be better if you look at it again anyway, one doesn't usually have a good solution until the 3rd or 4th attempt at solving the problem.
Related
Especially Ctrl+I , which is "mail this page". I'm using wordpress self hosted. So far I've found this code, not sure how to implement it or if it's old.
Please no plethora of reasons as to why you find this attempt pointless.
Really, shouldn't answer, but:
There's no reason for this, because there's always a very easy way around it. It'll probably take a lot more work than whatever you end up with's worth. If somebody has half of a computer literate mind, they probably can get past this without a problem at all.
Summary:
Don't bother
Disabling hotkeys won't stop anyone from just selecting that option from the File menu.
People will always find ways around these kinds of hacks. Turning off JavaScript, hacking the source with Firebug, Option+Click on a Mac, taking a screenshot, etc. They are completely ineffective against anyone even slightly determined to do what you don't want them to do.
You can't really do that. See this page for really good information on the portability of various key events in JavaScript across multiple browsers. You will see for one that each browser handles/responds to various key events in many different ways.
Also, most of the default browser actions (e.g. Ctrl-F, Ctrl-S) cannot be canceled if you are capturing key events. You can still detect some of them and respond, but you can't actually stop the browser from displaying the search dialog or whatever specific action is to be performed by the key combination.
Also, if someone really wants to take your page's HTML/JavaScript code or content, these methods won't stop them. The disable right click code from the link you referenced can prevent right click, but all someone has to do is disable javascript and it no longer works.
ASP.NET, web form model.
Is there any sample code/site that demonstrate a couple samples for regular website patterns/ templates? Like if I want to use tab to switch between different pages, should I put the code in a single page or in different page, and treat each tab as a page.
Or if in a search page (just a single search bar and button), should I display my result panel in same page using dynamically enable the result panel, or just to another page?
I want to find a general design pattern/ template. Please advise, thanks.
I don't know if this answer will be helpful to you or not. Correct me if I am wrong.
You are specifying demonstration about web designing. It seems the functionality you want is clearly saying to choose from weather you want to use AJAX or not. I suggest why don't you use jQuery Framework for all this functionality.
I would give this a read and consider what best fits your application and your programming style, no one size fits all with paterns.
http://msdn.microsoft.com/en-us/magazine/dd252940.aspx
After you have a general idea, head over to google.com and look for the patterns that catch your eye for simple tutorials
Edit:
For the specific question about whether you should modularize your code. The answer is almost always yes. If you think there is a chance that the component will be used somewhere else then doing this a head of time can save you a lot of headache later. This practice also makes maintaining a lot easier because it gives a clear scope of what could be causing a bug. Instead of having to look threw an entire page of unrelated code for things changing state unexpectedly in the page life cycle.
I am a quite new to web development and I am trying to do some small form updates without causing a postback. For example making a control visible when a drop down list is changed.
I have so far come across some features that achieve this like the RequiredFieldValidator inside an update panels. However, these are specific to a single task.
What are my options to achieve these client side updates in Visual Studio? At the moment I don't know any JavaScript, so I would prefer another solution if it exists.
If you don't know JQuery you should or at least any other Javascript library this will give you an edge and also pump up your resume. The learning curve of these JS frameworks is so short that you'll be creating awesome UI's in no time. I suggest that you take at least two hours to get to know JQuery you won't regret it.
Here's a few great article on using ASP.NET with JQuery:
http://dotnetslackers.com/articles/ajax/using-jquery-with-asp-net.aspx
http://www.dotnetspark.com/kb/1532-gridview-and-jquery-asp-net-tutorial.aspx
http://www.beansoftware.com/ASP.NET-Tutorials/Using-jQuery-ASP.NET.aspx
Here are a few of the best tutorials on JQuery:
http://www.ajaxline.com/best-jquery-tutorials-march-2010
For display functionality like you have described, javascript really is the best solution. Take a look at jQuery, it makes writing javascript a lot easier, and you should be up and running with it in no time for tasks like your basic show/hide functionality.
Unfortunately, AJAX stands for 'Asynchronous Javascript and XML' so getting this behaviour without using Javascript is going to land you in a bit of a pickle.
Update Panels do work and are very easy, but they're also very slow in comparison as even if you only see the contents of your panel update, the entire ASP page has to be executed.
I'd urge you to take a deep breath and head over to JQuery.Com and practise the tutorials there. Javascript is easier then you think and JQuery takes a lot of the hardships of cross-browser compatibility out of the picture, leaving you to focus on the real tasks.
Good Luck!
Is there any problem with using jquery layout plugin (there are several) to layout a page as opposed to using CSS and fixing browser compatibility issues myself?
Another problem is that the page has to fully load and download the javascript, then get rendered. This will slow down the page significantly.
The most obvious problem is that any visitor to the page using a browser with JavaScript turned off will not get the layout. If you're willing to turn away from those people, that may not be a blocking factor for you.
There can also be performance issues, delays on resizing the browser window, that sort of thing.
I'm not saying don't do it; if it's appropriate for your target audience. But look to see if you can avoid it or at least gracefully degrade if JavaScript isn't enabled. (Turn off JavaScript and come here to SO, for instance; still very usable in a read-only way.)
If doing this, continue to be sure to mark up your content in the main page (rather than only adding it dynamically) and use the most semantic markup you can, to improve your search-ability.
When your layout doesn't behave for whatever reason (and that will happen), will you be able to understand the code behind the JQuery plugin to fix it?
Invest in yourself and learn CSS properly, it's not hard, it doesn't take long and it will equip you for the future, don't just rely on plugins. Now I'm not saying never use a plug-in, but this to me seems inappropriate use
Does anyone know much about the Asp.Net webconfig element ?
I'm looking at it because I'm implementing an MS Ajax updatepanel in an existing site,
and after doing some looking around, on the web I'm not finding a lot of info about it.
And to avoid the flood of replies telling me how inefficient the update panel is, and that it's not actually providing any benefit etc. etc. I know! Let's say I've got my reasons for using it and leave it at that.
I guess my main question is;, will setting enableCompression="true" and enableCaching="true" help the performace of my update panel in any way?
Given the traversing of the DOM that is actually happening with an update panel it's generally not the content that is hindering performance.. it is the PC/Browser.
I know this is exactly what you aren't looking for but unless your panel contains a significant amount of data then compression and caching isn't going to help you terribly.
I took this from the scriptresourcehandler documentation:
By default, the ScriptResourceHandler class compresses and caches embedded script files for Internet Explorer 7.
So I don't think you'll see any difference if you set enableCompression/enableCaching true because it's already happening if you're using IE7.