Solved

Button used for hyperlink

Posted on 2010-11-17
8
4,780 Views
Last Modified: 2013-08-16
With the help from someone on this forum, I have created a hyperlink for one of my controls.

My next step is to turn this hyperlink into a button so the path of the link is not shown, but the user will just push the button.

I want to do this because I want to add a rule to close the form once the button is pressed, after the hyperlink is opened.  Right now, I cannot do this if they are just clicking the hyperlink.  I need to get the original form to close to avoid having both open at the same time.

Please let me know if I’m not clear….I look forward to your responses as always....thanks for the super help !!!
0
Comment
Question by:actolex
8 Comments
 
LVL 11

Expert Comment

by:N R
ID: 34157812
Do you mean like this?

<a href="http://domain.com/yourlink">Button</a>
0
 

Author Comment

by:actolex
ID: 34157916
Is this that the rule to assign the button?

Sorry....I'm a newbie to InfoPath.
0
 
LVL 28

Expert Comment

by:clayfox
ID: 34158667
In infopath they have hyperlink controls but not as button actions.

I think you can do them with code but the simple fix that I have done is use the hyperlink controls.

But then I right click on my buttons and go to borders and shading.

There I select none for the border and remove the shading.

Then I format the text of the buttons to make them underline.

The result is all of the buttons and hyperlinks look the same. I like it since it gives it more of a browser feel, which many users are accustomed to and it also makes the hypelinks and buttons indestinguishable.
0
 

Author Comment

by:actolex
ID: 34158709
I think I'm trying to do the opposite....make a hyperlink look like a button.

If it needs code, I may have to keep the hyperlink.  If I do need to keep it, can I :

Change the text of the hyperlink and not display the path
Add a function to close the current form once the hyperlink is clicked

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 28

Expert Comment

by:clayfox
ID: 34158739
The hyperlink control allows you to set the text and the actual link seperately.

You can only close the form on a button if you use actions.

So you will have to decide what way works the best for you.
0
 
LVL 15

Accepted Solution

by:
melli111 earned 500 total points
ID: 34165481
If you do decide to go with the code method, I just happened to have wrote this code for someone else.  The code below uses a field from the form as the url.... but if your url is always the same (i.e. www.woot.com) then you can replace the field xpath (that's what is in the quotes in the code) with the www url.

here's the instructions I already had written:

, so we need to change the form to c#
•      Tools
•      Form Options
•      Programming
•      For the “Form Template Code Language” select C# from the dropdown list
•      Ok

Now, let’s go back to that button we just added:
•      Double-click the button to open the properties
•      In the General tab make sure the Action is marked as Rules & Custom Code
•      Click “Edit Form Code”
•      We’re going to put code where it says “//write your code here” (so you can delete that comment; comments in code are in green and have no functionality)
•      Paste this into that spot:

XPathNavigator nav = MainDataSource.CreateNavigator();
            string hyplink = nav.SelectSingleNode("enter the XPath Here (steps below – keep the quotes", NamespaceManager).Value;
            System.Diagnostics.Process.Start(hyplink);
            this.Close();

•      Get the xpath of the field the hyperlink is currently created in:
o      Go to your InfoPath form
o      Open the DataSource pane
o      Right click on the field that stores the hyperlink
o      Click Copy XPath
•      Paste that into the quotes over my note above

The full code is below
using Microsoft.Office.InfoPath;

using System;

using System.Windows.Forms;

using System.Xml;

using System.Xml.XPath;

using mshtml;



namespace testbuttonhyperlink

{

    public partial class FormCode

    {

        // Member variables are not supported in browser-enabled forms.

        // Instead, write and read these values from the FormState

        // dictionary using code such as the following:

        //

        // private object _memberVariable

        // {

        //     get

        //     {

        //         return FormState["_memberVariable"];

        //     }

        //     set

        //     {

        //         FormState["_memberVariable"] = value;

        //     }

        // }



        // NOTE: The following procedure is required by Microsoft Office InfoPath.

        // It can be modified using Microsoft Office InfoPath.

        public void InternalStartup()

        {

            ((ButtonEvent)EventManager.ControlEvents["CTRL2_5"]).Clicked += new ClickedEventHandler(CTRL2_5_Clicked);

        }



        public void CTRL2_5_Clicked(object sender, ClickedEventArgs e)

        {

            XPathNavigator nav = MainDataSource.CreateNavigator();

            string hyplink = nav.SelectSingleNode("/my:myFields/my:field1", NamespaceManager).Value;

            System.Diagnostics.Process.Start(hyplink);

            this.Close();



        }

    }

}

Open in new window

0
 

Author Closing Comment

by:actolex
ID: 34165518
Awesome answer !!!!
0
 

Expert Comment

by:darkdell
ID: 39415233
The last line of code throw an error

this.Close();

InfoPath 2007 Developer Intella-sence finds the "this"  but no ".Close" What's the deal?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Before you can digitally sign infopath forms, you must have a digital certificate. Microsoft Certificate Services will need to be enabled on a Windows Server 2008 to facilitate the creation and verification of the digital certifciates on the web ser…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now