Have some problems with client side validation (using RequiredFieldValidator, RegularExpressionValidator, CustomValidator with client side validation logic). It seems that WebForm_DoPostBackWithOptions is not fired or causes unhandled exception that makes the form to do the postback regardless it's valid or not.
I tried using a ValidationSummary, hiding it if javascript is supported:
<script>
$(document).ready(function() {
$("#javascriptDisabled").hide();
}
</script>
...
<div id="javascriptDisabled">
<asp:ValidationSummary runat="server" ...>
</div>
...
<asp:Button runat="server" OnClick="SendMessage" ...>
My .cs code is:
protected void SendMessage(object sender, EventArgs e)
{
if(!Page.IsValid) return;
}
Every thing works fine on Chrome with disabled javascript on my laptop, but not on my Android phone. The problem is that on the phone Javascript is not disabled, it's enabled, and correctly hides the ValidationSummary, but does not perform client side validation for some reason that i can't understand (no developers tools on Android browser :(( ).
This is very frustrating! :(
Someone can help?
Thanks!
EDIT: I found the cause (but not the solution, if one exists). I'm using in my page a Telerik RadEditor control that, if the client is Android default browser, does not correctly render all the embedded scripts that are required, causing javascript exceptions and (probably) the disactivation of javascript runtime by the browser. This causes the client side validation not working anymore. Will investigate with Telerik if there is a solution to this issue.
Try with fiddler. When I tryied, I must setup the emulator to work via fiddler proxy. Doing that in my app (I'm also putting data on a .NET authenticated WS), it worked.
Saludos, OSCAR.
EDIT: I found the cause (but not the solution, if one exists). I'm using in my page a Telerik RadEditor control that, if the client is Android default browser, does not correctly render all the embedded scripts that are required, causing javascript exceptions and (probably) the disactivation of javascript runtime by the browser. This causes the client side validation not working anymore. Will investigate with Telerik if there is a solution to this issue.
Related
I have a successfully running signalr project where the work is done from an html page. I have taken the exact same html and pasted it into a .aspx page (with no master).
The signalr connection fails from the .aspx page giving error: Error during negotiation request
Has anyone any idea why this is. The code is exactly the same in the html and the .aspx page.
Have not included code here as it is working from the html page but if someone needs it please just ask.
Gave up late last night, woke up and first thing I thought of was so blindingly obvious but will post here anyway in case it helps someone else - by moving to a .aspx page, a postback occurs when the input button is clicked (obviously)!. Anyway so by just adding return false; to the javascript button onclick function resolved the issue and am now able to connect to signalr.
I have developed a web site and used update panel controls on all pages. The site was working fine and partial rendering was also working fine. But today update panel just stopped doing any post back. I don't know if this has anything to do with Performance Analysis, since I was experimenting with it yesterday.
I am using Asp.NET AJAX 3.5 framework, ToolkitScriptManager on all pages.
Things I tried doing.
1.) Reloaded Binary for AJAX Control Toolkit
2.) Tried to reload update panel
3.) Page methods within Update Panel seems to work. And Autocomplete Extender is working appropriately.
4.) I did backed up my code from few weeks back. It is working as expected. So I tried to copy web.config from my backup and checked it on latest code. Still not working.
Currently on any page whenever I select an item from a dropdownlist it is not doing a typical asynchronous postback and doesn't load other dependent dropdownlists.
Also update panel is not working on any of my pages. There seems to be an issue related to web.config but not sure though(I also added a new web config file but not working).
Any help in related to this would be appreciated.
Thank You.
I have solved this problem. Cause: I have written "Response.write()" in my master page. I was able to track in Chrome Console window and this was error: Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. I removed response.write and it works as it was supposed to be.
Same thing as #Mitul but it was a Response.Redirect().
It works on localhost but not in production.
I added and works everywhere !
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="lnkAddProduct" />
</Triggers>
The "lnkAddProduct" is a LinkButton in a Panel.
I am wondering are there any standard mechanisms available to protect the asp.net asp code in the client browser ? I found some references to Windows script encoders. Question is, are these script encoders encodes both aspx and code behind source ? If aspx is encoded with the Windows script encoders then how client browsers can decode it? Are they aware of the encoding algorithms ?
Or can we control the client browsers ( IE, Firefox, Chrome etc) to disable the view source option in the Tasks Menu when web site a loaded in them?
Any pointers will be appreciated.
The HTML code generated on a webpage is by definition public. It has to be accessible to the browser for it to be able to render the page properly. You will not find a reliable solution to hide the view source option in browsers.
To explain the basics a little bit :
When you create a page, you write markup in your .aspx file and some c# source code in the .aspx.cs file. The c# code is the server side code, which means that it is executed on the server (as opposed to, say, javascript which is executed directly in the client's browser -- client side).
When a page request is executed, the ASP.NET engine executes the server side code, and also executes the asp tags that you wrote in the .aspx page (for example : <asp:Button runat='server'... /> . It then spits out HTML code (this is a very simplified version of what actually happens).
The client's browser only ever gets the HTML (and it will not see the C# code nor any of asp markup code which is used to generate your page).
As I said before, the HTML generated is, and will always be public. There is nothing you can do to reliably hide it.
Server-side code (ie. code in code-behind pages, controllers, helpers, <% code nuggets %>, etc) will of course never be visible to a web client.
Your aspx or view pages (ie. .aspx, .cshtml, .vbhtml) files will also not be visible to web clients unless you have a signficiant security vulnerability, but the HTML generated by said files will be, along with any outputted or referenced JavaScript.
If the client couldn't read the HTML or JavaScript, how would the web browser be able to parse it?
Here's a question about obfuscating JavaScript, which will at least hinder but not completely remove a user's ability to view your source: How can I obfuscate (protect) JavaScript?
Similarly, one could theoretically obfuscate outputted HTML as well, but it could also be likely be reversed with some work.
It is impossible for the user to see your server-side (C#) source.
It is impossible to stop the user from seeing your client-side (HTML & Javascript) source.
In terms of javascript - the only thing you can do is obfuscate it to an extent that makes it worthless for someone to try to understand.
None of the code behind code is sent down to the client, only the rendered HTML.
there is no way to completely remove the ability for a client to view the source of your HTML. The only thing you can do is to obfuscate your HTML to make it harder for them to tell what they're looking at.
There are many libraries out there for obfuscating HTML in .net if you do a google search.
I'm confused really, but...
If you are on about the ASP.NET markup, you need not worry as any request to an ASP.NET page will cause the page to be compiled (if it hasn't already been, or isn't cached) which renders the page content as HTML.
If you are worried about people navigating to your code behind (e.g. mysite.com/SomePage.aspx.cs), you need not worry, as ASP.NET will not serve that content [unless the standard configuration has been changed].
If you are worried about people accessing your code through FTP, then I would suggest you change your compilation method and not deploy the source.
Am I missing anything?
I develop a web application which uses a lot of JavaScript. I developed first portion of code on my machine and everything works just fine. Problems occurred after deploying to remote machine to IIS - the page runs but i.e. whole validation that I wrote doesn't run - I've checked under FF, IE6, IE7.. Are there any IIS properties to set to make it run?
EDIT
I've just found out that the problem is here:
<script type="text/javascript">
function validate() {
return validateTrees();
}
</script>
The validate() function is called here:
<asp:Button ID="btnSubmit" CssClass="button" runat="server" OnClientClick="return validate();" Text="Send for approval" />
And validateTrees() function is loaded dynamically from .js file by the control:
<cust:CustomTreeControl ID="CustomTreeControl 1" runat="server" />
which is placed just before this submit button. It seems that after deploy the browser can't find validateTrees() function.
IIS shouldn't affect your JS in anyway (as long as the JS files are present and accessed properly).
Could you post some code examples of what you have (simple test cases, preferably) and what you expect it to do and what it isn't doing, and what, if any, errors you are getting.
IIS has nothing to do with this.
Your javascript files are downloaded by the browser on the client machine and runs there, not on the server.
Make sure you published your files correct.
Javascript typically runs on the client not the server. What makes you think this has anything to do with IIS?
Use a tool such as fiddler to confirm the browser is receiving all the content your expect.
Ok, that was silly, I didn't update paths to scripts after deployment.
This one has been a stumper for me. Its very easy to duplicate though a rather obscure issue. It came about as I was doing some javascript work on a web page yet also make use of the validation controls that ASP.NET provides.
Some specifics up front: using a Vista-based development machine with the 3.5 framework and IIS 7. I also have a QA machine that is running windows server 2003, also with the 3.5 framework but running IIS 6.
Take a page with a simple TextBox, Validation Control, and button to submit them. For example:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Text is Required" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
Simple ASP.NET validation control code here ... The idea here is that client-side validation code is generated for the required field and a postback is not done unless the text box has a field. If the browser does not support client-side scripting, then ASP.NET will catch it on the server side using the Page.IsValid property.
When I run this from my Vista-based development machine, the client-side scripting code is generated for both IE and Firefox and works just fine.
When I run from the win2003-based QA machine, client side code for the validator controls is also generated for both browsers. The validation code for IE works fine ... but does Not work for Firefox. When the submit button is pressed (with an empty text box), the client-side code appears to be ignored and a postback performed. Now the validation error is caught server side - but I want to know why its not working client side in the first place.
The interesting quirk here is that if I take page source views under Firefox from the Development machine (the one that works) and the QA machine (the one that doesn't) and compare them - the client side validation code is dramatically different.
Ideas on what to change to get the client side validation code to work in Firefox with the QA machine?
UPDATE: Had a few comments asking to see the generated source. I've saved the Dev and QA source as .htm files and zipped them up. You can get them at http://www.optsolutions.com/testvalidation.zip
Check your web.config for xhtmlconformance and make sure it is not set to legacy.
http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx
I am having the same issue with a similar setup. Differences in the browserCaps settings is the most promising possibility I have come across so far.
http://msdn.microsoft.com/en-us/library/sk9az15a(VS.80).aspx