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

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
 
F

Family Tree Mike

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"?
 
L

Luc

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"?
 
G

Guest

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

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top