1 //------------------------------------------------------------------------------
2 // <copyright file="WmlHyperLinkAdapter.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 #if WMLSUPPORT
8 
9 namespace System.Web.UI.WebControls.Adapters {
10     using System.Web;
11     using System.Web.UI.WebControls;
12     using System.Web.Security;
13     using System.Web.Util;
14 
15     public class WmlHyperLinkAdapter : HyperLinkAdapter {
16 
Render(HtmlTextWriter markupWriter)17         protected internal override void Render(HtmlTextWriter markupWriter) {
18             WmlTextWriter writer = (WmlTextWriter)markupWriter;
19             String targetUrl = Control.NavigateUrl;
20 
21             String text = Control.Text;
22             if (text.Length == 0) {
23                 // Whidbey 18195 UNDONE: This solution is somewhat ad hoc, awaiting spec resolution on IStaticTextControl
24                 // in M2.  For now, take text from first IStaticTextControl or DataboundLiteralControl.
25                 foreach(Control child in Control.Controls) {
26                     if (child is IStaticTextControl) {
27                         text = ((IStaticTextControl)child).Text;
28                         break;
29                     }
30                     else if (child is DataBoundLiteralControl) {
31                         text = ((DataBoundLiteralControl)child).Text;
32                         break;
33                     }
34                 }
35             }
36 
37             String softkeyLabel = Control.SoftkeyLabel;
38             if (softkeyLabel.Length == 0) {
39                 softkeyLabel = Control.Text;
40             }
41             writer.EnterStyle(Control.ControlStyle);
42             // AUI 3652
43             targetUrl = Control.ResolveClientUrl(targetUrl);
44 
45             targetUrl = Control.GetCountClickUrl(targetUrl);
46 
47             // If cookieless mode is on, we need to apply the app path modifier for if the request is authenticated
48             HttpContext context = HttpContext.Current;
49             Debug.Assert(context != null);
50             bool cookieless = CookielessHelperClass.UseCookieless(context, false, FormsAuthentication.CookieMode);
51             if (cookieless && context.Request != null && context.Request.IsAuthenticated && context.Response != null) {
52                 targetUrl = context.Response.ApplyAppPathModifier(targetUrl);
53             }
54 
55             PageAdapter.RenderBeginHyperlink(writer, targetUrl, false /* encode, Whidbey 111129 */, softkeyLabel, Control.AccessKey);
56             String source = Control.ImageUrl;
57             if (Control.ImageUrl != null && Control.ImageUrl.Length > 0) {
58                 writer.RenderImage(source, null /* localsource */, text /* alternateText */);
59             }
60             else {
61                 writer.Write(text);
62             }
63             PageAdapter.RenderEndHyperlink(writer);
64             writer.ExitStyle(Control.ControlStyle);
65         }
66     }
67 }
68 
69 #endif
70