RequiredFieldValidators issue in Asp.net - asp.net

I am in the process of adding RequiredFieldValidators into my form and just tested it on the web and received this error
Error
WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).
I added the solution which was this in the web.config file:
<appsettings> <add value="None" key="ValidationSettings:UnobtrusiveValidationMode"></add> </appsettings>
But that prompted this error
Error
HTTP Error 500.19 - Internal Server Error
This last error is saying something is wrong with the solution I inputted above.. Has anyone else ever run into this and have a solution?

Hope you have set targetFramework to 4.5 . The full config should look like this.
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"></add>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic. If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.
Reminder: <appSettings> parent in the web.Config file should be the root element, that is <configuration>.
Helpful links - http://www.codeproject.com/Articles/465613/WebForms-UnobtrusiveValidationMode-requires-a
http://msdn.microsoft.com/en-us/library/system.web.ui.unobtrusivevalidationmode.aspx -- This says it a feature of v4.5, you should have to specify targetFramework = 4.5 in cofig to make it work.

Related

How <compilation targetFramework = "4.x.x" /> and <httpRuntime targetFramework = "4.y.y" /> works together?

I understand all .net 4.x.x release versions are in place upgrade. I already read post and similar SO question but still I don’t fully understand application runtime behavior in context of below two configuration settings in my application :
<compilation debug="true" targetFramework="4.x.x" />
<httpRuntime targetFramework="4.y.y" />
I understand that setting <httpRuntime targetFramework="4.y.y" /> is just short form and it actually expands to below settings :
<compilation targetFramework="" />
<machineKey compatibilityMode="" />
<pages controlRenderingCompatibilityVersion="" />
Assuming above understanding of mine is correct, I would like to validate same and clear below doubts :
If <compilation targetFramework /> setting is already there, then I assume it overrides the one generated because of <httpRuntime targetFramework />
For example, if both below settings below are present in my web.config :
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.7.2" />
Then effectively to runtime this means :
<compilation targetFramework="4.6.1" />
<machineKey compatibilityMode="" />
<pages controlRenderingCompatibilityVersion="" />
I am finding difficult to understand what setting above tells runtime that application is compiled against 4.6.1 but wants to leverage features of .net framework installed on target machine (say 4.7.2) OR what setting tells runtime that application does not want to leverage 4.7.2 features and would prefer to run under quirk mode.

Cannot use the Session variable

after many research in Google, i didn't found the solution to my problem.
When i want to make enter value to the Session variable, all is ok :
Session["idResult"] = youthID;
but when i want to get the value with the line code :
youthID = (int)Session["idResult"];
i get the error :
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.
i tried to add in the web.config :
EnableSessionState="True"
and also :
<httpModules><add name="Session" type="System.Web.SessionState.SessionStateModule"/> </httpModules>
<pages enableSessionState="true"/>
and many other possibilities but it's doesn't work
my default web.config is :
> <?xml version="1.0"?> <!-- For more information on how to configure
> your ASP.NET application, please visit
> http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration>
> <system.web>
> <compilation debug="true" targetFramework="4.5"/>
> <httpRuntime targetFramework="4.5"/> </system.web> </configuration>

Server Exception With ASPX

When I run aspx code through web server I get the following exception. What should I do to fix it ?
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
Source Error:
Line 9: <system.web>
Line 10:<customErrors mode="Off"/>
Line 11: <compilation debug="true" targetFramework="4.5" />
Line 12:<httpRuntime targetFramework="4.5" />
Line 13: </system.web>
It is because of the below cases:
Your Application pool may configured for the .net framework version 2.0.
Or the framework 4.5 may not be installed on your server.
Make sure the framework is registered with the IIS.
Go to "Website" in IIS -> Start Options -> build tab – > Select Target Framework in combo box (.NET FrameWork 4.5)
There's no targetFramework attribute for the <httpRuntime> node. You should remove it from your web.config:
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime />
</system.web>
Also make sure that you have configured the IIS application pool to use the correct version of the .NET framework.

Updated ASP.NET 3.5 to 4.0 -> Sys.WebForms.PageRequestManager is undefined

As the title indicates, I recently updated an ASP.NET 3.5 application containing UpdatePanels and similar AJAX technologies to ASP.NET 4.0. Unfortunately, the UpdatePanels work no more and full page postbacks makes it all go south.
Web.config-file
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"/>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging"/>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
</configSections>
<system.net>
<mailSettings>
<smtp>
<network host="localhost"/>
</smtp>
</mailSettings>
</system.net>
<system.web>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms">
<forms loginUrl="~/Login.aspx" name=".ASPXFORMSAUTH" defaultUrl="~/Administration/SystemEvents.aspx"/>
</authentication>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace. -->
<customErrors mode="RemoteOnly" defaultRedirect="~/Error.aspx">
<error statusCode="401" redirect="~/Unauthorized.aspx"/>
</customErrors>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Javascript error upon execution in Chrome:
Uncaught TypeError: Object function Function() { [native code] } has no method '_registerScript'
Uncaught TypeError: Cannot read property 'PageRequestManager' of undefined
What is there that I could've done wrong? Thank you!
Set EnablePartialRendering="false" in ScriptManager
I was having trouble with this recently as I was updating an older project and followed your steps above but it was still giving me the same error. I found that I needed to update a line in the web.config file which fixed it.
I changed:
<xhtmlConformance mode="Legacy"/>
to:
<xhtmlConformance mode="Transitional"/>
... and I've solved it myself by replacing the UpdatePanels and by removing the scripting managers.
I know this post is very old but the way I solved this problem its not given here.. So I thought its not bad to add one more way.
I tried doing
Set EnablePartialRendering="false" in ScriptManager
and it worked but then for every click the page was getting fully loaded which I didnt wanted.
so What I did is I just added a Line in Page_Load(). btnexport is button id.
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnexport);
I first tried it outside postback but my requirements were to export even after every dropdown click which was in update panel so the button wasnt working for that.
then when I put it inside postback... voila!! It worked like a charm.
So, you can put it outside or inside postback according to your requirements.
OR
One more solution - You can do this-
You might have forgot to add trigger inside asp:updatepanel like me.
Add this inside updatepanel and voila!!
<Triggers>
<asp:PostBackTrigger ControlID="btnexport" />
</Triggers>

Publish is not transforming web.config?

I made a web.config (full file, it doesn't show XML errors)
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
...
<location path="." inheritInChildApplications="false">
<connectionStrings>
<add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
<add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
</connectionStrings>
</location>
...
with a transform file (web.Staging.config)
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="database"
connectionString="c"
providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<customErrors defaultRedirect="error.aspx"
mode="RemoteOnly" xdt:Transform="Replace">
</customErrors>
</system.web>
</configuration>
I am publishing in Staging mode (right click website > Publish > Method: File System ...)
------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
MySystem -> D:\Project\bin\Staging\MySystem.dll
...
But when I look at the web.config in the output folder it isn't changed.
I found the following on the Build log:
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.
What could be the problem? Am I doing this right?
Answering late but perhaps I can save someone a headache. In Visual Studio 2013, there are two places to select configuration for your build and deploy. The Configuration Manager and then again with Publish Web where the third step in the Wizard entitled Settings allows you to select Config you want to use. If you don't select your new configuration it will use the transform for the selected configuration instead of yours.
I found out two things:
You cannot set a namespace on the <configuration> tag (ex: for <location path="." inheritInChildApplications="false">)
You have to watch for the correct hierarchy in the transform file.
Like
<configuration>
<location>
<connectionStrings>
Instead of
<configuration>
<connectionStrings>
Ensure that in the properties of the Web.Config file Build Action is set to Content.
If the build action is set to None, it will not be transformed, even if it is being copied to the output directory.
Make sure to include InsertIfMissing if the section you are trying to add does not already appear in the output.
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<security xdt:Transform="InsertIfMissing">
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>
</location>
</configuration>
Don't forget to copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically and of course there will be no match...
Answering late as well, but this may help someone.
I realized that if you have two websites in the same solution, when you try to publish one of them the transformation might not work if you have one only configuration for both projects.
One of my websites was always transforming, but the other sometimes was and sometimes wasn't.
For example, I had the configuration "Auto" in the solution, and had web.Auto.config for both websites.
I resolved that by creating a new configuration with a different name - "AutoAdmin" - creating also its web.AutoAdmin.config file for the second project, and when I published it again the transformation finally occurred.
I followed the below steps to fix this issue. Thanks, #michaelhawkins for pointing in the right direction. You need to make sure you change the configuration to release in two places.
And right click on your project and select "Properties". IF not working try selecting x86 in CPU Architecture
#Karthikeyan VK your post resolved my issue. Although I was selecting Production configuration in my publish profile, in configuration manager it was set to dev therefore It didn't transform my settings.
Microsoft needs to fix this bug. Once you pick a configuration in the publishing profile it should automatically update the configuration manager as well.

Resources