How come classes in subfolders in my App_Code folder are not being found correctly?
Solution 1
You need to add codeSubDirectories to your compilation element in web.config
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="View"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
Solution 2
Check for BuildAction property of file. This should be set to "Compile"
Solution 3
Is it possible that you haven't set the folder as an application in IIS (or your web server)? If not, then the App_Code that gets used is that from the parent folder (or the next application upwards).
Ensure that the folder is marked as an application, and uses the correct version of ASP.NET.
Solution 4
It might not be the correct way but I find it the easiest.
Create the class in the main Folder as usual, then move it with your mouse to your sub-folder. Re-compile and all should be fine.
edgarmtze
Updated on June 16, 2022Comments
-
edgarmtze almost 2 years
I have a html like
<div class='form-field-box even' id="one_field_box"> <div class='form-display-as-box' id="one_display_as_box"> one<span class='required'>*</span> : </div> <select id='one' name='one' data-placeholder="Select one" class="chzn-select" style="width:300px;" tabindex="4"> <option value='0'></option> <option value='Corto' selected='selected' >Corto</option> <option value='Largo' >Largo</option> </select> <div class="form-error"></div> <div class='clear'></div> </div>
And I have a script:
function validate(id, error) { var obj = $('#' + id); if(obj.val() == '0' || obj.val() == ''){ obj.parent().parent().find('.form-error').html(error); return true; } return false; }
I call this function:
validate('one', "error in field one.");
I am not getting correct navigation, could you please help me correct validate() function ?
-
j08691 about 11 yearsWhat do you mean by "I am not getting correct navigation"? What errors are you getting or what's not happening that you think should be?
-
edgarmtze about 11 yearswell the message error is not displaying because it is not finding correct id="one"
-
PSL about 11 years@cMinor --> if you are not able to fin the correct id="one" make sure you give a context during selection using jquery i.e $('#'+id,'idofthecontext')
-
-
Greg over 15 yearsClasses in my App_Code folder directly work, if I put App_Code/View or something I get the error for classes in the View Sub-Directory
-
edgarmtze about 11 yearsHow do I pass id parameter or where the function Knows I want
id="one"
to give an example... -
edgarmtze about 11 yearsHow could I call this to validate several fields depending on id?
-
awbergs about 11 yearsNot sure what you're asking exactly but your validate function has an id param so i'm using that to construct the form id. Are you saying you won't have the id parameter available?
-
edgarmtze about 11 yearsif I need to navigate through different
#one_field_box
i would need to pass those ids as parameters? -
Amy about 11 years@cMinor I add a selector to easily find the elements to validate, then run each of them through the
validate()
function. See jsfiddle.net/amyamy86/9CC2b -
edgarmtze about 11 yearsNo wait, I tested And it works perfectly, thank you very much
-
PSL about 11 years@cMinor first of all i would suggest refrain from using multiple elements with same id. instead provide them all the same class name and a data attribute to specify the error message ex:- data-error = "Name Cannot be empty" and then use $('.classname').each(call validate here with $(this)) remove the code var obj = $('#' + id); from your validate function and directly deal with the object and for error message get the message from $(obj).data('error').