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?
 
kahvedzicConnect With a Mentor Author 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
 
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
All Courses

From novice to tech pro — start learning today.