Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Open the Phone number on phone pad when the link is clicked

Hi Experts,

I have a link button with a phone number.
<div>
<asp:LinkButton  ID="lblMobilePhone" runat="server"></asp:LinkButton>
</Div>

When I click the link button it should open the phone number on the phone pad. I know how to do it when the link is inside a gridview. But how to do it if it is out side inside a DIV tag.
Thanks.
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Set the text to be whatever text you want and the PostBackURL to the tel link:

eg:
  <asp:LinkButton runat="server" ID="lb1" PostBackUrl="tel:8585551212" Text="Dial Me"></asp:LinkButton>

you can also control these properties from the code behind.
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

ASKER

Thank you very much for you reply. I do not want static values. I want something like this. But it does not work.

<asp:linkbutton ID="lblMobilePhone" runat="server" href='<%# String.Format("tel:" & lblMobilePhone.Text)%>'></asp:linkbutton>

Phone number is coming from the DB. I want the same number to pop up.

Thanks.
<asp:LinkButton runat="server" ID="lb1" PostBackUrl='<%# String.Format("tel:"& lblMobilePhone.Text)%>' Text='<%#  lblMobilePhone.Text %>' ></asp:LinkButton>

You have to set both the post back URL and the text url.

Also you should be binding to the source directly, not to some other control.

MVC or Webforms . . . you might be better of just doing this from the code behind when you get the response back from the DB.
Can u please tell me how to do it code behind?
This is my code.
Dim cmd As New SqlCommand
            cmd.CommandText = "Select * from CUSTCONTACT where Id=" & ContactID
            con.Open()
            cmd.Connection = con
            Reader = cmd.ExecuteReader()

            While Reader.Read
                 lnkHomePhone.Text = Reader.Item("HomePhone").ToString
             End While
            con.Close()
               

Thanks.
I would change your code to following

I am not sure if telephone bit will work but atleast it will be more efficient

Dim cmd As New SqlCommand
            cmd.CommandText = "Select Top 1 HomePhone from CUSTCONTACT where Id=" & ContactID
            con.Open()
            cmd.Connection = con
            Dim Phone as Object = cmd.ExecuteScalar()

            If Not IsDBNull(Phone) Then
                 lnkHomePhone.Text = "tel:" & Phone
             End If
            con.Close()

Open in new window

Thank you for your reply. But it is not working. When I give lnkHomePhone.Text = "tel:" & Phone, It is coming as "tel:219-545-5240" .

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Does it work if you modify the HomePhone field in DB to contain a valid phone number (starting with 0 or 00, no spaces or dashes etc)?
It worked!! Thank you very much for your help.