how to know whether a hyperlink is entered in a textbox?

  • Thread starter Thread starter Luc
  • Start date Start date
L

Luc

Hi,

I want to know whether a hyperlink is enterd in a textbox. An user enters
this string into a textbox: <a href='http://...'>click</a>
In order to know that, i tried to know whether the string "click" was typed
in the textbox.

This is what i did:
<asp:TextBox ID="TextBox1" TextMode="MultiLine"
runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hl As String = "click"
Dim x As Integer
Dim txt as string = TextBox1.text

x = txt.IndexOf(hl)
if x>0 then
response.write("yes")
else
response.write("yes")
end if

End Using

But this gives 0 .

Is there a way to determine whether "click" is entered, or is there a way to
determine whether a hyperlink is entered in the textbox?
Thanks
Luc
 
Luc said:
Hi,

I want to know whether a hyperlink is enterd in a textbox. An user enters
this string into a textbox: <a href='http://...'>click</a>
In order to know that, i tried to know whether the string "click" was typed
in the textbox.

This is what i did:
<asp:TextBox ID="TextBox1" TextMode="MultiLine"
runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hl As String = "click"
Dim x As Integer
Dim txt as string = TextBox1.text

x = txt.IndexOf(hl)
if x>0 then
response.write("yes")
else
response.write("yes")
end if

End Using

But this gives 0 .

Is there a way to determine whether "click" is entered, or is there a way to
determine whether a hyperlink is entered in the textbox?
Thanks
Luc

Your intended code works for me. I say intended because you have a "End
Using" with no using statement, and you write "Yes" in both clauses of
the test.

By the way, you must be overriding the setting of Page.ValidateRequest
in order to accept the url in a text box.

If you are testing for a url though, why depend on the user including
the word "click"?
 
Thanks

Family Tree Mike said:
Your intended code works for me. I say intended because you have a "End
Using" with no using statement, and you write "Yes" in both clauses of the
test.

By the way, you must be overriding the setting of Page.ValidateRequest in
order to accept the url in a text box.

If you are testing for a url though, why depend on the user including the
word "click"?
 
Hi,

I want to know whether a hyperlink is enterd in a textbox. An user enters
this string into a textbox: <a href='http://...'>click</a>
In order to know that, i tried to know whether the string "click" was typed
in the textbox.

This is what i did:
 <asp:TextBox ID="TextBox1" TextMode="MultiLine"
runat="server"></asp:TextBox>
 <asp:Button ID="Button1" runat="server" Text="Button" />

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hl As String = "click"
Dim x As Integer
Dim txt as string = TextBox1.text

x = txt.IndexOf(hl)
if x>0 then
response.write("yes")
else
response.write("yes")
end if

End Using

But this gives 0 .

Is there a way to determine whether "click" is entered, or is there a wayto
determine whether a hyperlink is entered in the textbox?
Thanks
Luc

It depends on what you finally need to do. For instance, beside the
code you can try to use client-side script, or a CompareValidator
control to validate against a specific value...
 
Back
Top