user528690
user528690

Reputation: 3

Error handling when inserting a null value, asp.net c#

i have a webpage built in asp.net c#. it always a user to create a new record in a db table. there are there are two input fields, text and score. text cannot be a null value so if the user doesn't input text onsubmit, the page errors out. i want to throw in some simple error handling code in the code behind page. i've tried including an if/else on_inserted method but ran into some java script errors. any help would be apprieciated. thanks.

aspx page -----------------

 <EditItemTemplate>
                  <customEditors:EditorWithCustomButtons_1 runat="server" ID="Editor1" Content='<%# Bind("userText") %>' />

                </EditItemTemplate>
                <InsertItemTemplate>
                  <customEditors:EditorWithCustomButtons_1 runat="server" ID="Editor1" Content='<%# Bind("userText") %>' />
                </InsertItemTemplate>

Upvotes: 0

Views: 371

Answers (2)

Ives.me
Ives.me

Reputation: 2394

               <asp:RequiredFieldValidator id="RequiredFieldValidator2"
                ControlToValidate="TextBox1"
                Display="Static"
                ErrorMessage="*"
                runat="server"/> 

Also don't forget to use page is valid before saving to the database.

if (page.isValid){
//send to db
}

Upvotes: 0

Artemiy
Artemiy

Reputation: 1979

why not use RequiredFieldValidator validator? it works inside the grid

Upvotes: 1

Related Questions