Note that there are some explanatory texts on larger screens.

plurals
  1. PORequiredFieldValidator not preventing database from getting updated with an empty row - Visual Studio 2012
    primarykey
    data
    text
    <p>I'm just playing around with Visual Studio 2012 and trying to make an very simple newssite with an local SQL Server database. The problem is that the RequiredFieldValidator is not working on the textboxes. Even if the boxes are empty the database still gets updated with an empty record and i just dont know why as the validator was working fine in VS2010. If i press the submit button the errors are showing up but the database still getting updated with an empty record. Anyone have a clue why? I'm using ScriptResourceMapping in the C# file of the form if that is making any difference. </p> <p>Here's my code:</p> <pre><code> &lt;section id="addnews_panel"&gt; &lt;h2&gt;Rubrik&lt;/h2&gt; &lt;asp:TextBox ID="txtHeadlineForm1" runat="server" Width="332px" CausesValidation="True" ValidationGroup="newsForm"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtHeadlineForm1" ErrorMessage="Write something" ValidationGroup="newsForm"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;h2&gt;Rubrik 2&lt;/h2&gt; &lt;asp:TextBox ID="txtHeadlineForm2" runat="server" Width="328px" CausesValidation="True" ValidationGroup="newsForm"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtHeadlineForm2" ErrorMessage="Write something" ValidationGroup="newsForm"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;h2&gt;Ingress&lt;/h2&gt; &lt;asp:TextBox ID="txtIngressForm" runat="server" Height="99px" TextMode="MultiLine" Width="325px" CausesValidation="True" ValidationGroup="newsForm"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtIngressForm" ErrorMessage="Write something" ValidationGroup="newsForm"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;h2&gt;Nyhet&lt;/h2&gt; &lt;asp:TextBox ID="txtNewsForm" runat="server" Height="288px" TextMode="MultiLine" Width="507px" CausesValidation="True" ValidationGroup="newsForm"&gt;&lt;/asp:TextBox&gt; &lt;br /&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNewsForm" ErrorMessage="Write something" ValidationGroup="newsForm"&gt;&lt;/asp:RequiredFieldValidator&gt; &lt;br /&gt; &lt;asp:Button ID="btnAddNews" runat="server" Text="Lägg till nyhet" OnClick="btnAddNews_Click" ValidationGroup="newsForm" /&gt; &lt;h2&gt; &lt;asp:Label ID="lblResult" runat="server"&gt;&lt;/asp:Label&gt; &lt;/h2&gt; &lt;/section&gt; protected void btnAddNews_Click(object sender, EventArgs e) { using (dbnewsEntities db = new dbnewsEntities()) { var addNews = new tblNews(); addNews.headline = txtHeadlineForm1.Text; addNews.headline2 = txtHeadlineForm2.Text; addNews.ingress = txtIngressForm.Text; addNews.news = txtNewsForm.Text; addNews.date = DateTime.Now.ToString(); db.tblNews.Add(addNews); db.SaveChanges(); } lblResult.Text = "News added!"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload