How to insert form data into a database with validations in asp.net? -



How to insert form data into a database with validations in asp.net? -

i trying build web application requires users register themselves. added custom validators , other validators according need.

part of code in .aspx file

<form id="form" name="form" action="../hi.aspx" method="post"> <table cellspacing="4" class="style1"> <tr> <td class="style4"> <asp:textbox id="txtfirstname" runat="server" width="157px"></asp:textbox> </td> td class="style5" id="fname"> <asp:customvalidator id="customvalidator1" runat="server" controltovalidate="txtfirstname" errormessage="your first name should @ to the lowest degree 2 characters long" onservervalidate="customvalidator1_servervalidate" forecolor="red" validateemptytext="true"></asp:customvalidator>...

and correspnding code in .aspx.cs file is

protected void customvalidator1_servervalidate(object source, servervalidateeventargs args) { args.isvalid = (args.value.length>1); }

this works fine when run part of application.

now, want retrieve values of text fields , store them in database.

in aspx.cs file, wrote code as

protected void buttonregister_click(object sender, eventargs e) { string fname = txtfirstname.text; controllers.registrationcontroller r = new controllers.registrationcontroller(); int = r.registerdata(fname); if (a==1) { response.redirect("../hi.aspx"); } }

which called when submit button clicked.

the registerdata() method in registrationcontroller established connection database , stores form values. connection established correctly , values retrieved , stored. but, problem is, when phone call registerdata() method method buttonregister_click, validation have written doesn't work. entered in form gets stored database without validation.

how retrieve values , store them , @ same time ensure beingness validated?

i new .net, help appreciated.

thank much in advance.

you phone call page.validate within click method , check result of or specifying causesvalidation on button should cause valdation run

in long term though might want @ moving rules lower lower (ie. business logic) such when/if move supporting services wont have reimplement rules in services, of course of study if you're not ever planning getting away them on ui may suffice

asp.net validation

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -