InfoPath Form HyperLink Open in Same Window

Problem: The hyperlink control in a browser enabled infopath form opens up in a new window. This might not be a good thing as a usability perspective. It might work for some and might not for many. This post is for those ‘many’.

Solution:

Note: This solution is valid only for the forms with managed code behind.

The solution I have is very trivial. Just drop a button on the form, stylize it to change its look and feel like an hyperlink. Then on the button click event of the form, just redirect the page to the URL you wanted to. There is a catch or two here.

A) On the click event, you make sure that the existing web request is completed before redirecting to your desierd page. So the code should look something like this:

HttpContext.Current.Response.Redirect(“http://somesite.com/page.html”,  false);

Passing the second parameter as ‘false’ we are ensuring that the current web request is completed and then redirected.

B) To make the button to be a hyperlink you need to do the following:

Right click the button select ‘borders and shading’, select None under presets. Then under the ‘shading’ tab select the radio button for ‘No color’. Then change the font color to blue(hyperlinks are usually blue) and make it underlined.

After doign all this there is still one thing that remains, i.e the mouse turning into a hand on hover over the button. To accomplish this, from file menu, select save as source files. From the source files, edit the view1.xls file, to set the style to cursor:pointer for the button element. Then open up the manifest.xsf in design mode. You will see the button as an hyper link including mouse hover.

Update (09/03/09):

There is a kind of caveat for the above implementation. Whenever the Response.Redirect is done, the new page from code behind of the InfoPath Form, eventhough the page is redirected, the URL in the browser address bar remains the same. It behaves as the Server.Transfer method.

To fix this anomaly the workaround is redirect to an intermediary page which in turn redirects to the actual page you want to redirect. The intermediary page could be a simple page with java script redirect method.

10 Responses

  1. Hi

    I have asked on the MS forum about this issue at http://social.msdn.microsoft.com/Forums/en-US/sharepointinfopath/thread/edf402a3-5467-426a-a533-3c5029fbc360 – basically, an InfoPath developer on our team states, that option A is not doable from an InfoPath codebehind – the HttpContext.Current is null, she says.

    Is there something specific that needs to be set, enabled or something to get it to work?

    • Hi,
      I am posting the reply to the MS forum.
      If the form is deployed as a web compatible form in sharepoint site or as a matter of fact if it is hosted in an asp .net page, it should have the HttpContext. There is nothing specific need to be done for this.

      Adding System.Web as reference and including the using system.web statement is required to compile the code behind project for the form.

      Thanks!

  2. Hi

    I haven’t seen your answer on the forums?

    anyway, our developer tested this, and in the code behind for the form, the HttpContext.Current is null. The fact that she can get to the HttpContext.Current obejct means that she has referenced the right assemblies. If she calls a .NET assembly that is in the GAC, from the code behind, she can get to the HttpContext.Current, but doing a Response.Redirect does not do anything.. Are there any special settings required? Shoudl the form have a digital signature? Ane special trust settings? Anything else?


    eliasen

    • I am not able to post in the forum. Once I click reply it is leading to my profile page. Yes, the form I am using has ‘full trust’ settings. It need not have a digital signature.

      If its a showstopper for you, I can email you the sample form/code I am using.

      -Srinivas

      • Hi

        Our developer asked me to ask you if you ahve tried this on MOSS 2007 Enterprise Edition with the form running under Forms Server? Or is you used WSS or perhaps another version of MOSS or something?

        Thanks!


        eliasen

        • Hi, I was not able to find your email in your blog/site. I will try to upload and provide a link when I get a chance. I am using MOSS 2007 Enterprise edition. Browser enabled InfopathForms can work only in enterprise edition. So I assume you too are using the enterprise edition.

          Thx! Srinivas

  3. Emailing me the sample code would be great! Thanks.

    You can find my email address on my blog at http://blog.eliasen.dk

    Thanks!

  4. […] InfoPath HyperLink Redirect Filed under: Infopath, Redirect — sladescross @ 4:22 pm https://sharenotes.wordpress.com/2009/08/13/infopath-form-hyperlink-open-in-same-window/ […]

  5. how to redirect form in new window using infopath, i would need this as sharevis form has help content

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: