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.
RadhaKrishnaKiJayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
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.
RadhaKrishnaKiJayaAuthor Commented:
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.
Kyle AbrahamsSenior .Net DeveloperCommented:
<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.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

RadhaKrishnaKiJayaAuthor Commented:
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.
CodeCruiserCommented:
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

RadhaKrishnaKiJayaAuthor Commented:
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.
Kyle AbrahamsSenior .Net DeveloperCommented:
       While Reader.Read
                 lnkHomePhone.Text = Reader.Item("HomePhone").ToString
                 lnkHomePhone.PostBackUrl = "tel:" + Reader.Item("HomePhone").ToString
             End While

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
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)?
RadhaKrishnaKiJayaAuthor Commented:
It worked!! Thank you very much for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.