asp.net form view insert mode msgbox

Hi,
I create a form view insert template for inserting new data in sql table. One of the fields is mandatory and can not be null. What I want to do is to make message box if user click on insert button before typing text in this field. I dont want to use required field validator, just message box.  Here is my code behind(vb).With this code behind When insert is clicked I have error that null can`t be inserted and then on default page displayed Insert Name text.


Thanks for help.
Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim namebox As TextBox
        namebox = FormView1.FindControl("NameTextBox")

        If namebox.Text = "" Then
            Response.Write("scriptlanguage='javascript'>alert('Insert Name');</script>")
        End If
    End Sub

Open in new window

LVL 1
kahvedzicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krunal_shahCommented:
where is your code ragarding insert?
where you are getting error "null can't be inserted" ?

try this,
Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim namebox As TextBox
        namebox = FormView1.FindControl("NameTextBox")
 
        If namebox.Text = "" Then
            Response.Write("scriptlanguage='javascript'>alert('Insert Name');</script>")
            return
        End If
    End Sub
0
rajapandian_81Commented:
Change the line
Response.Write("scriptlanguage='javascript'>alert('Insert Name');</script>")

to
Response.Write("<script language='javascript'>alert('Insert Name');</script>");

I can't see any code to insert value...
0
kahvedzicAuthor Commented:
After all I add Required Field Validator for those text box fields that are mandatory, this way I have no error displaying if the fields are empty and have a user info message to enter text to mandatory fields. Anyway, thanks for help guys.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.