Answered by:
RequiredField Validation in visual studio 2013

Question
-
User1441157511 posted
I used a required field validation control to validate a textbox using the following lines of codes
<asp:Label ID="Label25" runat="server" Text="School"></asp:Label>
<asp:TextBox ID="schl" runat="server" Width ="320px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="schl" Text="*"></asp:RequiredFieldValidator>
<asp:Button ID="addschool" runat="server" Text="Add" CssClass="button" BackColor="#333333" BorderColor="Silver" OnClick="addschool_Click" BorderWidth="2px" Width="150px" />this is the back code of the button
protected void addschool_Click(object sender, EventArgs e) { try { if (Page.IsValid) { error.Text = ""; MySqlConnection conn = new MySqlConnection(connection); MySqlCommand addschool = new MySqlCommand("insert into pla20132014.schools (Departments, Schools) values(@dept, @schl)", conn); MySqlDataReader read; conn.Open(); addschool.Parameters.Add("@dept", MySqlDbType.VarChar).Value = dept.Text; addschool.Parameters.Add("@schl", MySqlDbType.VarChar).Value = schl.Text; read = addschool.ExecuteReader(); read.Close(); conn.Close(); error.ForeColor = Color.Green; error.Text = "Upload Successful"; } } catch(MySqlException myex) { error.Text = myex.Message; } catch(Exception ex) { error.Text = "/n " + ex.Message; } }
but i receive the following error in stack trace
[InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).] System.Web.UI.ClientScriptManager.EnsureJqueryRegistered() +2287754 System.Web.UI.WebControls.BaseValidator.RegisterUnobtrusiveScript() +10 System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +9831213 System.Web.UI.Control.PreRenderRecursiveInternal() +83 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Control.PreRenderRecursiveInternal() +155 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
i really don't know what is wrong because i use same code in visual studio 2010 and it works perfectly. Thanks for your assistance
Thursday, June 25, 2015 2:34 PM
Answers
-
User2024324573 posted
Well, to get the idea how the files are created and organized in App_Start folder do the following steps:
- Create a new MVC Web Site project (Don't select the Empty template)
- When the project has been created, open the solution explorer and find App_Start folder and you will see there are 5 file (.cs) files there.
- One of them is BundleConfig.cs, open file and see what is there, bundled packages for js, css and other files from the folders of your project.
- The bundle names are being called in your .Layout.cshtml files so that all the pages are rendered with the scripts added as bundles.
Hope this will help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 2, 2015 5:52 PM
All replies
-
User2024324573 posted
Do you have jquery.validate.js installed and reference in your page?
Thursday, June 25, 2015 3:54 PM -
User1441157511 posted
i have just downloaded the jQuery 2.1.4 package but can't find it in my add reference. am i looking in the wrong place or i am not doing the right thing?Thursday, June 25, 2015 5:42 PM -
User2024324573 posted
You need to add it to BundleConfig.cs in App_Start folder, please follow the way how other packages are added there.
Thursday, June 25, 2015 6:18 PM -
User1441157511 posted
i'm using the c# language. there is no App_Start folder in my project because i created it from scratch. so i don't kn how to implement that. Thanks
Thursday, July 2, 2015 7:41 AM -
User2024324573 posted
Well, to get the idea how the files are created and organized in App_Start folder do the following steps:
- Create a new MVC Web Site project (Don't select the Empty template)
- When the project has been created, open the solution explorer and find App_Start folder and you will see there are 5 file (.cs) files there.
- One of them is BundleConfig.cs, open file and see what is there, bundled packages for js, css and other files from the folders of your project.
- The bundle names are being called in your .Layout.cshtml files so that all the pages are rendered with the scripts added as bundles.
Hope this will help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 2, 2015 5:52 PM