开发者

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") %>' />

               开发者_如何学Go </EditItemTemplate>
                <InsertItemTemplate>
                  <customEditors:EditorWithCustomButtons_1 runat="server" ID="Editor1" Content='<%# Bind("userText") %>' />
                </InsertItemTemplate>


why not use RequiredFieldValidator validator? it works inside the grid


               <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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜