Firrst, i have a textbox to allow users to input related hyperlinks. Therefore, users are to enter the links lik this in the textbox.
http://www.yahoo.com,http://www.asp.net
However, when some1 clicks on the link, it appears http://www.yahoo.com,http://www.asp.net in the address bar. Can some1 teach me how to seperate this 2 sites so that it appears http://www.yahoo.com or just http://www.asp.net in the address bar How to seperate them The text box is a single line text box.
Secondly, the websites have to input with this format http://www.yahoo.com. can anyone tell me how to detect whether the user has input the website with the http:// in front or else prompt an error message
I really am not so good at coding. If some1 can help me here, I'll b really thankful!
Here's the code so far:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.Control
Imports System.Drawing
Imports Image = System.Drawing.Image
Imports System.IO
Imports System.ComponentModel
Public Class insert Inherits System.Web.UI.Page
'Dim strConnection As String = "Server=MLS\MLS;Database=e-snippet;Integrated Security=SSPI;"
Dim strConnection As String = "Data Source=localhost;Initial Catalog=mLS;Integrated Security=True;"
Dim objConnection As New SqlConnection(strConnection)
Protected WithEvents snipName As System.Web.UI.WebControls.TextBox
Protected WithEvents snipBasic As System.Web.UI.WebControls.TextBox
Protected WithEvents snipDetail As System.Web.UI.WebControls.TextBox
Protected WithEvents snipImg As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents Submit As System.Web.UI.WebControls.Button
Protected WithEvents Reset As System.Web.UI.WebControls.Button
Protected WithEvents Back As System.Web.UI.WebControls.Button
Protected WithEvents snipWeb As System.Web.UI.WebControls.TextBox
Protected WithEvents snipNameValid As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents snipCatValid As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents snipBasicValid As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents snipDetailValid As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents snipGloss As System.Web.UI.WebControls.TextBox
Protected WithEvents snipWebValid As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents addsnippet As System.Web.UI.WebControls.Label
Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents File2 As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents add_r3_c5 As System.Web.UI.HtmlControls.HtmlImage
Dim ObjDataAdapter As New SqlDataAdapter
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents check As System.Web.UI.WebControls.Label
Protected WithEvents Contri As System.Web.UI.WebControls.Label
Protected WithEvents Contributor As System.Web.UI.WebControls.TextBox
Protected WithEvents snipCat As System.Web.UI.WebControls.DropDownList
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Session("userID") Is Nothing Then
Response.Redirect("index.aspx")
ElseIf Not Page.IsPostBack Then
' Populate Category Dropdownlist
FillCategoryData()
End If
' Get Role & Username
Contributor.Text = Session("userID")
End Sub
Public Sub FillCategoryData()
Dim strCategory As String
strCategory = "SELECT * FROM Category"
Dim cmdGetCategory As New SqlCommand(strCategory, objConnection)
' Open Connection
objConnection.Open()
Dim objReader As SqlDataReader = cmdGetCategory.ExecuteReader()
snipCat.DataSource = objReader
snipCat.DataTextField = "main_category"
snipCat.DataValueField = "category_id"
snipCat.DataBind()
snipCat.Items.Insert(0, New ListItem(" SELECT A CATEGORY "))
' Close Connection
objConnection.Close()
End Sub
Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
Response.Redirect("snippet.aspx")
End Sub
Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click
Try
' --- CHECK FOR DUPLICATE RECORDS ---
Dim strDupCheck As String = "SELECT Count(*) FROM General " & _
"WHERE term = @term AND main_category = @categoryID"
Dim cmdDupCheck As New SqlCommand(strDupCheck, objConnection)
cmdDupCheck.Parameters.Add(New SqlParameter("@term", SqlDbType.VarChar, 20))
cmdDupCheck.Parameters("@term").Value = snipName.Text\
cmdDupCheck.Parameters.Add(New SqlParameter("@categoryID", SqlDbType.Int, 4))
cmdDupCheck.Parameters("@categoryID").Value = snipCat.SelectedItem.Value
' Open Connection
objConnection.Open()
Dim recordCount As Integer = cmdDupCheck.ExecuteScalar()
If recordCount <> 0 Then
' Display Duplicate Error Msg
RegisterStartupScript("showErrMessage", "<script language=""JavaScript""> alert('Snippet: " & snipName.Text & " already exists in the database.');</script>")
Return
End If
' Check If Connection is Open
If (objConnection.State = ConnectionState.Open) Then
objConnection.Close()
End If
'Grab name of image file
Dim strFileName As String = CStr(snipImg.PostedFile.FileName)
Dim strFileType As String = CStr(snipImg.PostedFile.ContentType)
Dim strFileSize As String = CStr(snipImg.PostedFile.ContentLength)
Dim splitName() As String = strFileName.Split("\")
Dim splitType() As String = strFileType.Split("/")
Dim serverDirectory As String = "C:\Inetpub\wwwroot\mLS\Uploads\Images\" & splitName(splitName.Length - 1)
Dim FileName As String = splitName(splitName.Length - 1)
Response.Write(splitName(splitName.Length - 1) & "<br/>")
Response.Write(splitType(0) & "<br/>")
If splitType(0) = "image" Then
snipImg.PostedFile.SaveAs(serverDirectory)
insertData(FileName)
ElseIf FileName = "" Then
insertData(FileName)
Else
RegisterStartupScript("showErrMessage", "<script language=""JavaScript""> alert('Invalid File Type');</script>")
End If
Catch ex As Exception
check.Text = ex.Message
End Try
End Sub
Public Sub insertData(ByVal FileName As String)
Try
'Insert values
Dim strInsert As String
strInsert = "INSERT INTO " & _
"General(term, category_id, main_category, standard_info, extended_info, extended_img, full_info, key_word, user_role, Contributor) " & _
"VALUES(@Term, @catNo, @catName, @shortInfo, @longInfo, @imgFile, @links, @word, @role, @userID)"
' Declare local variables and objects
Dim cmdInsert As New SqlCommand(strInsert, objConnection)
cmdInsert.Parameters.Add(New SqlParameter("@Term", SqlDbType.VarChar, 150))
cmdInsert.Parameters("@Term").Value = snipName.Text
cmdInsert.Parameters.Add(New SqlParameter("@catNo", SqlDbType.Int, 4))
cmdInsert.Parameters("@catNo").Value = snipCat.SelectedItem.Value
cmdInsert.Parameters.Add(New SqlParameter("@catName", SqlDbType.VarChar, 50))
cmdInsert.Parameters("@catName").Value = snipCat.SelectedItem.Text
cmdInsert.Parameters.Add(New SqlParameter("@shortInfo", SqlDbType.VarChar, 255))
cmdInsert.Parameters("@shortInfo").Value = snipBasic.Text
cmdInsert.Parameters.Add(New SqlParameter("@longInfo", SqlDbType.VarChar, 1000))cmdInsert.Parameters("@longInfo").Value = snipDetail.Text
cmdInsert.Parameters.Add(New SqlParameter("@imgFile", SqlDbType.VarChar, 50))
cmdInsert.Parameters("@imgFile").Value = FileName
cmdInsert.Parameters.Add(New SqlParameter("@links", SqlDbType.VarChar, 200))
cmdInsert.Parameters("@links").Value = snipWeb.Text
cmdInsert.Parameters.Add(New SqlParameter("@word", SqlDbType.VarChar, 200))
cmdInsert.Parameters("@word").Value = snipGloss.Text
cmdInsert.Parameters.Add(New SqlParameter("@role", SqlDbType.Char, 10))
cmdInsert.Parameters("@role").Value = Session("userRole")
cmdInsert.Parameters.Add(New SqlParameter("@userID", SqlDbType.VarChar, 50))cmdInsert.Parameters("@userID").Value = Session("userID")
objConnection.Open()
cmdInsert.ExecuteNonQuery()
'Response.Write(strInsert)
Dim strGetID = "SELECT snippet_id FROM General WHERE term='" & snipName.Text.ToString() & "'"
Dim cmdGetID As New SqlCommand(strGetID, objConnection)
Dim idReader As SqlDataReader = cmdGetID.ExecuteReader()
idReader.Read()
Dim strAddMeta As String = "INSERT INTO MetaData(snippet_id, contributor, role, creation_date, key_word) " & _
"VALUES(@snippetID, @contributor, @role, @datetime, @keyword)"
Dim cmdAddMeta As New SqlCommand(strAddMeta, objConnection)
' Add Parameters for Meta Command
cmdAddMeta.Parameters.Add(New SqlParameter("@snippetID", SqlDbType.Int, 4))cmdAddMeta.Parameters("@snippetID").Value = idReader("snippet_id")
idReader.Close()
cmdAddMeta.Parameters.Add(New SqlParameter("@contributor", SqlDbType.VarChar, 20))cmdAddMeta.Parameters("@contributor").Value = Contributor.Text
cmdAddMeta.Parameters.Add(New SqlParameter("@role", SqlDbType.VarChar, 20))cmdAddMeta.Parameters("@role").Value = Session("RoleName")
Dim dateMeta As DateTime
dateMeta = DateTime.Now()
cmdAddMeta.Parameters.Add(New SqlParameter("@datetime", SqlDbType.DateTime, 8))
cmdAddMeta.Parameters("@datetime").Value = dateMeta
cmdAddMeta.Parameters.Add(New SqlParameter("@keyword", SqlDbType.VarChar, 50))cmdAddMeta.Parameters("@keyword").Value = snipGloss.Text
' Execute cmdAddMeta to Insert MetaData
cmdAddMeta.ExecuteNonQuery()
Response.Redirect("snippet.aspx")
Catch ex As Exception
check.Visible = True
check.Text = ex.Message
addsnippet.Visible = False
End Try
objConnection.Close()
End Sub
Private Sub snipCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipCat.SelectedIndexChanged
End Sub
Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.Click
snipName.Text = ""
snipGloss.Text = ""
snipBasic.Text = ""
snipDetail.Text = ""
snipWeb.Text = ""
End Sub
Private Sub snipWeb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipWeb.TextChanged
End Sub
Private Sub snipBasic_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipBasic.TextChanged
End Sub
Private Sub snipDetail_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipDetail.TextChanged
End Sub
Private Sub ClearSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
The green part is the part for the textbox

Problem With A split function and a Regex Validator
Paul Gerald
No, I'm saying (guessing) that after the user has entered the links and you've displayed them, you're also going to need to store them somewhere, like in your database, so that they can be used.
But I think one step at a time.
I don't know about that error message, I'm afraid I haven't done much with the web services stuff in VS, but if it's complaining about modal dialogs then that would make sense (the msgbox is a modal dialog).
nextpaco
Why did you start a new thread about this
Anyway, I know you say you suck at coding, but if you really suck, then I'd wager that you're doing this because you have to (rather than wanting to) in which case I'd also wager that it's important that you learn what you're doing. So just take a moment to think about what it is you want.
You have your two pieces of code. The first one handles what happens when the text in the textbox changes (TextChanged event) and splits up your string into a string array.
Private Sub snipWeb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipWeb.TextChanged
Dim Str() As String
Str = snipWeb.Text.Split(",")
End Sub
Saiboro
1) Don't call .Split on the textbox, but rather the Textbox's .Text property.
str = snipWeb.Text.split(",")
2) Regex is a shared class and does not need the following line:
Dim Regex as Boolean
Instead, change the following line to
Return System.Text.RegularExpressions.Regex.IsMatch(strIn, "^(http|ftp|https)\://[a-zA-Z0-9\-\.]+[a-zA-Z]{2,3}(/\S*) $")
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
bopritchard
Ohh yea I kind of understand the concept but i suck at the execution.
So u mean I have to write a new sub, then put that code in and use the message box to validate the error
Is that it Sorry I'm really bad at programming ! but realli a big thank you for your help!
Shadi_05
Blipwort
Yea u are partly right. I am tasked to correct the errors on an existing program and its really confusing cos the progam lacks alot comment from the previous person and it takes alot time to understand it.
well ,
now do some code to actually store the links somewhere or whatever else you need to do.
So u mean I have to declare a variable and then use it to store the links the user has entered. Wouldnt it give this problem as well Str is a string array whereas the function wants a string.
And what is this error about
It is invalid to show a modal dialog or form when the application is not running in UserInteractive mode. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
is it a problem with the msgbox
Alibong
Firrst, i have a textbox to allow users to input related hyperlinks. Therefore, users are to enter the links lik this in the textbox.
http://www.yahoo.com,http://www.asp.net
However, when some1 clicks on the link, it appears http://www.yahoo.com,http://www.asp.net in the address bar. Can some1 teach me how to seperate this 2 sites so that it appears http://www.yahoo.com or just http://www.asp.net in the address bar How to seperate them The text box is a single line text box.
Secondly, the websites have to input with this format http://www.yahoo.com. can anyone tell me how to detect whether the user has input the website with the http:// in front or else prompt an error message
I really am not so good at coding. If some1 can help me here, I'll b really thankful!
Imports
System.DataImports
System.Data.SqlClientImports
System.Web.UI.ControlImports
System.DrawingImports
Image = System.Drawing.ImageImports
System.IOImports
System.ComponentModelImports
System.Security.CodeAccessPermissionPublic
Class insert Inherits System.Web.UI.Page 'Dim strConnection As String = "Server=MLS\MLS;Database=e-snippet;Integrated Security=SSPI;" Dim strConnection As String = "Data Source=localhost;Initial Catalog=mLS;Integrated Security=True;" Dim objConnection As New SqlConnection(strConnection) Protected WithEvents snipName As System.Web.UI.WebControls.TextBox Protected WithEvents snipBasic As System.Web.UI.WebControls.TextBox Protected WithEvents snipDetail As System.Web.UI.WebControls.TextBox Protected WithEvents snipImg As System.Web.UI.HtmlControls.HtmlInputFile Protected WithEvents Submit As System.Web.UI.WebControls.Button Protected WithEvents Reset As System.Web.UI.WebControls.Button Protected WithEvents Back As System.Web.UI.WebControls.Button Protected WithEvents snipWeb As System.Web.UI.WebControls.TextBox Protected WithEvents snipNameValid As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents snipCatValid As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents snipBasicValid As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents snipDetailValid As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents snipGloss As System.Web.UI.WebControls.TextBox
Protected WithEvents snipWebValid As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents addsnippet As System.Web.UI.WebControls.Label Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile Protected WithEvents File2 As System.Web.UI.HtmlControls.HtmlInputFile Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents add_r3_c5 As System.Web.UI.HtmlControls.HtmlImage Dim ObjDataAdapter As New SqlDataAdapter#
Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer.<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent() End Sub Protected WithEvents check As System.Web.UI.WebControls.Label Protected WithEvents Contri As System.Web.UI.WebControls.Label Protected WithEvents Contributor As System.Web.UI.WebControls.TextBox Protected WithEvents snipCat As System.Web.UI.WebControls.DropDownList 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor.InitializeComponent()
End Sub#
End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Session("userID") Is Nothing ThenResponse.Redirect("index.aspx")
ElseIf Not Page.IsPostBack Then ' Populate Category DropdownlistFillCategoryData()
End If ' Get Role & UsernameContributor.Text = Session("userID")
End Sub Public Sub FillCategoryData() Dim strCategory As StringstrCategory = "SELECT * FROM Category"
Dim cmdGetCategory As New SqlCommand(strCategory, objConnection) ' Open ConnectionobjConnection.Open()
Dim objReader As SqlDataReader = cmdGetCategory.ExecuteReader()snipCat.DataSource = objReader
snipCat.DataTextField = "main_category"
snipCat.DataValueField = "category_id"
snipCat.DataBind()
snipCat.Items.Insert(0,
New ListItem(" SELECT A CATEGORY ")) ' Close ConnectionobjConnection.Close()
End Sub Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.ClickResponse.Redirect("snippet.aspx")
End Sub Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click Try ' --- CHECK FOR DUPLICATE RECORDS --- Dim strDupCheck As String = "SELECT Count(*) FROM General " & _"WHERE term = @term AND main_category = @categoryID"
Dim cmdDupCheck As New SqlCommand(strDupCheck, objConnection)cmdDupCheck.Parameters.Add(
New SqlParameter("@term", SqlDbType.VarChar, 20))cmdDupCheck.Parameters("@term").Value = snipName.Text
cmdDupCheck.Parameters.Add(
New SqlParameter("@categoryID", SqlDbType.Int, 4))cmdDupCheck.Parameters("@categoryID").Value = snipCat.SelectedItem.Value
' Open ConnectionobjConnection.Open()
Dim recordCount As Integer = cmdDupCheck.ExecuteScalar() If recordCount <> 0 Then ' Display Duplicate Error MsgRegisterStartupScript("showErrMessage", "<script language=""JavaScript""> alert('Snippet: " & snipName.Text & " already exists in the database.');</script>")
Return End If ' Check If Connection is Open If (objConnection.State = ConnectionState.Open) ThenobjConnection.Close()
End If 'Grab name of image file Dim strFileName As String = CStr(snipImg.PostedFile.FileName) Dim strFileType As String = CStr(snipImg.PostedFile.ContentType) Dim strFileSize As String = CStr(snipImg.PostedFile.ContentLength) Dim splitName() As String = strFileName.Split("\") Dim splitType() As String = strFileType.Split("/") Dim serverDirectory As String = "C:\Inetpub\wwwroot\mLS\Uploads\Images\" & splitName(splitName.Length - 1) Dim FileName As String = splitName(splitName.Length - 1)Response.Write(splitName(splitName.Length - 1) & "<br/>")
Response.Write(splitType(0) & "<br/>")
If splitType(0) = "image" ThensnipImg.PostedFile.SaveAs(serverDirectory)
insertData(FileName)
ElseIf FileName = "" TheninsertData(FileName)
ElseRegisterStartupScript("showErrMessage", "<script language=""JavaScript""> alert('Invalid File Type');</script>")
End If Catch ex As Exceptioncheck.Text = ex.Message
End Try End Sub Public Sub insertData(ByVal FileName As String) Try 'Insert values Dim strInsert As StringstrInsert = "INSERT INTO " & _
"General(term, category_id, main_category, standard_info, extended_info, extended_img, full_info, key_word, user_role, Contributor) " & _
"VALUES(@Term, @catNo, @catName, @shortInfo, @longInfo, @imgFile, @links, @word, @role, @userID)"
' Declare local variables and objects Dim cmdInsert As New SqlCommand(strInsert, objConnection)cmdInsert.Parameters.Add(
New SqlParameter("@Term", SqlDbType.VarChar, 150))cmdInsert.Parameters("@Term").Value = snipName.Text
cmdInsert.Parameters.Add(
New SqlParameter("@catNo", SqlDbType.Int, 4))cmdInsert.Parameters("@catNo").Value = snipCat.SelectedItem.Value
cmdInsert.Parameters.Add(
New SqlParameter("@catName", SqlDbType.VarChar, 50))cmdInsert.Parameters("@catName").Value = snipCat.SelectedItem.Text
cmdInsert.Parameters.Add(
New SqlParameter("@shortInfo", SqlDbType.VarChar, 255))cmdInsert.Parameters("@shortInfo").Value = snipBasic.Text
cmdInsert.Parameters.Add(
New SqlParameter("@longInfo", SqlDbType.VarChar, 1000))cmdInsert.Parameters("@longInfo").Value = snipDetail.Text
cmdInsert.Parameters.Add(
New SqlParameter("@imgFile", SqlDbType.VarChar, 50))cmdInsert.Parameters("@imgFile").Value = FileName
cmdInsert.Parameters.Add(
New SqlParameter("@links", SqlDbType.VarChar, 200))cmdInsert.Parameters("@links").Value = snipWeb.Text
cmdInsert.Parameters.Add(
New SqlParameter("@word", SqlDbType.VarChar, 200))cmdInsert.Parameters("@word").Value = snipGloss.Text
cmdInsert.Parameters.Add(
New SqlParameter("@role", SqlDbType.Char, 10))cmdInsert.Parameters("@role").Value = Session("userRole")
cmdInsert.Parameters.Add(
New SqlParameter("@userID", SqlDbType.VarChar, 50))cmdInsert.Parameters("@userID").Value = Session("userID")
objConnection.Open()
cmdInsert.ExecuteNonQuery()
'Response.Write(strInsert) Dim strGetID = "SELECT snippet_id FROM General WHERE term='" & snipName.Text.ToString() & "'" Dim cmdGetID As New SqlCommand(strGetID, objConnection) Dim idReader As SqlDataReader = cmdGetID.ExecuteReader()idReader.Read()
Dim strAddMeta As String = "INSERT INTO MetaData(snippet_id, contributor, role, creation_date, key_word) " & _"VALUES(@snippetID, @contributor, @role, @datetime, @keyword)"
Dim cmdAddMeta As New SqlCommand(strAddMeta, objConnection) ' Add Parameters for Meta CommandcmdAddMeta.Parameters.Add(
New SqlParameter("@snippetID", SqlDbType.Int, 4))cmdAddMeta.Parameters("@snippetID").Value = idReader("snippet_id")
idReader.Close()
cmdAddMeta.Parameters.Add(
New SqlParameter("@contributor", SqlDbType.VarChar, 20))cmdAddMeta.Parameters("@contributor").Value = Contributor.Text
cmdAddMeta.Parameters.Add(
New SqlParameter("@role", SqlDbType.VarChar, 20))cmdAddMeta.Parameters("@role").Value = Session("RoleName")
Dim dateMeta As DateTimedateMeta = DateTime.Now()
cmdAddMeta.Parameters.Add(
New SqlParameter("@datetime", SqlDbType.DateTime, 8))cmdAddMeta.Parameters("@datetime").Value = dateMeta
cmdAddMeta.Parameters.Add(
New SqlParameter("@keyword", SqlDbType.VarChar, 50))cmdAddMeta.Parameters("@keyword").Value = snipGloss.Text
' Execute cmdAddMeta to Insert MetaDatacmdAddMeta.ExecuteNonQuery()
Response.Redirect("snippet.aspx")
Catch ex As Exceptioncheck.Visible =
Truecheck.Text = ex.Message
addsnippet.Visible =
False End TryobjConnection.Close()
End Sub Private Sub snipCat_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipCat.SelectedIndexChanged End Sub Private Sub Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reset.ClicksnipName.Text = ""
snipGloss.Text = ""
snipBasic.Text = ""
snipDetail.Text = ""
snipWeb.Text = ""
End Sub
Private Sub snipWeb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipWeb.TextChanged Dim Str() As StringStr = snipWeb.Text.Split(",")
End Sub Private Function IsValidWeb(ByVal strIn As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(strIn, "^(http|ftp|https)\://[a-zA-Z0-9\-\.]+[a-zA-Z]{2,3}(/\S*) $") If Not IsValidWeb(strIn) Then MsgBox("invalid") End Function
Private Sub snipBasic_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipBasic.TextChanged End Sub Private Sub snipDetail_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipDetail.TextChanged End Sub Private Sub ClearSMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End SubEnd
Classcwest
Hi there Jim,
I have still this error from the first part
Str = snipWeb.Text.Split(",")
it says Argument not specified for parameter 'Number' of Public Function Str(Number As Object) As String'.
And as for the 2nd part
Return
System.Text.RegularExpressions.Regex.IsMatch(strIn, "^(http|ftp|https)\://[a-zA-Z0-9\-\.]+[a-zA-Z]{2,3}(/\S*) $") If Not IsValidWeb(strIn) Then MsgBox("Not valid!")there is no error but the validation doesn';t really work. Even when i tried to put in a wrong form of input, the msg box doesn't prompt an error.
rajjon
Others have mentioned the Regular Expression can be used to validate the url. It could also be used to locate all valid URL's in a string using the Matches collection. There are plenty of code examples around the internet for RegEx. You can find a number of url validators at www.regexlib.com.
Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
su45937
You might want to look at the string and text classes in the docs, another option is to start looking at regular expressions. Both of these methods will help with what you need to do but they will take some reading to get the task done... As you are new to the programming scene I would fistr try and get the application running where te user would enter one address at a time and learn to validate that first. Then move on to accepting multiple sites in the text.
Syed Faraz Mahmood
Hmm, yea so u mean jus declaring variables and storing AddressList in them
Yeap I think its the msgbox. It isnt able to display and if I change it to MessageBox.Show method, it can't work as well. =(
Woyler
SO the answers will still be the same as previous post on the same subject.
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=515069&SiteID=1
If you want to allow entry of the multiple addresses then the split method will allow you to separate the string into an array of strings. Then you can process each individually.
Each could be subjected to a regex validation to ensure that they are valid URL's - at least in the format of the strings.
If you do a split on the string and then use the string array element 0 in order to set the URL. Then you will display http://www.yahoo.com
The regex would enable you to validate the entered string - and display a suitable error message.
sroughley
Private
Sub snipWeb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles snipWeb.TextChanged Dim str() As Stringstr = snipWeb.split(",")
For Each s As String In strMsgBox(s)
Next End Sub
Private Function IsValidWeb(ByVal strIn As String) As Boolean Dim Regex As Boolean Return Regex.IsMatch(strIn, "^(http|ftp|https)\://[a-zA-Z0-9\-\.]+[a-zA-Z]{2,3}(/\S*) $") End FunctionNow this is my code. However, I still have 2 errors.
1) 'split' is not a member of 'System.Web.UI.WebControls.TextBox'
2) 'IsMatch" is not a member of 'Boolean"
Can some1 tel me how to solve the error Reall a big thank you
j_o_h_a_n_n_e_s
http://www.geocities.com/capre3diem87/screehshot.jpg
Here's the screenshot of the input page
http://www.geocities.com/capre3diem87/screenshot2.jpg
Here's the screenshot of the output page