locked
Link Control in MobileControls RRS feed

  • Question

  • User-2115551320 posted
    Hi!

    I´ve noticed that the Command control with the Format property set to "CommandFormat.Link" doesn't work with some devices. Therfore I would like to use the Link Control instead. But how can I get an event posted back to my app? Or can I somehow figure out in page_load that the user hit the Link Control?

    Thanx in advance

    Nicholas
    Wednesday, July 27, 2005 8:50 AM

All replies

  • User-95607119 posted
    Use button instead of link and command control.
    Wednesday, July 27, 2005 9:24 AM
  • User-2115551320 posted

    But what if want a Link?

    Thanx, Nicholas

    Wednesday, July 27, 2005 9:39 AM
  • User-95607119 posted
    Then you have to use some workaround. URL-s with parameters by example.
    Wednesday, July 27, 2005 11:29 AM
  • User-2115551320 posted
    OK, thank you!
    Thursday, July 28, 2005 1:33 AM
  • User-1361599924 posted

    I would say it's safest in most cases not to use the command button style = link setting to get button behaviour that looks like a link. (Unless you're absolutely sure all your mobile clients will be fine with it).

    Javascript is rendered by the MMIT to cause a button like postback when clicked.

    If a device doesn't support Javascript, the MMIT will output a HTML button automatically instead of something that looks like a link. (There goes consistency with your web apps look and feel).

    Further problem; if a device profile indicates that a given device does support javascript, but the user has turned off javascript on their device the button will be rendered looking like a link, but when the client clicks it, it won't work. (Worse still, some devices give an error about an invalid link).

    So, anyhow, I agree with Qnnn. If you want this behaviour in a link, create your own link back to the current page (sic) with an appended querystring parameter. Intercept that querystring parameter and raise a custom click event from within your codebehind class.

    The advice I've documented for my company is that we assume all devices don't support javascript regardless of what their device profile says. It's too much of a minefield - especially for a public mobile website that will have users with all sorts of unpredictable devices.

    If you ever do come up with a requirement/solution that absolutely requires javascript on the client device, you're going to have to make your users aware of that, and enable js on their device. The more mass market your website the less likely it is you'll be able to get full user buy in.

    Thursday, July 28, 2005 8:45 AM
  • User-2115551320 posted

    Thanks for your answer, I'll go for querystrings!

    Nicholas

    Friday, July 29, 2005 8:29 AM
  • User-2115551320 posted

    Hello again!

    It almost works! I've placed one Button, one Link and one TextBox control on a form and Link1.NavigateURL is set back to my app with querystring.

    I just have one big problem: my variable "TextBox1" is always empty when I click one the Link (works with the button).

    page_load()
    {

     if (TextBox1 = "xxxx"){
      // input value is "xxxx"
     }
    }

    Please Help.[:'(]

    Nicholas

    Monday, August 1, 2005 10:20 AM
  • User-1361599924 posted

    I just tried the following and it worked fine;

    private void Page_Load(object sender, System.EventArgs e)

    {

    if (Request.Params["boo"] != null)

    {

    Button1.Text = this.TextBox1.Text.ToString();

    }

    }

    If this isn't of help, please post your actual code so I can have a proper look at it.

    Tuesday, August 2, 2005 10:27 AM
  • User-2115551320 posted
    OK, here is the complete code. If you click on the Link the TextBox1 content will empty. That's the problem. I suspect that the browser doesn't post anything when you click the link and that's why TextBox1 is empty. But I'm new to this so I hope I'm wrong.

    public class MobileWebForm1 : System.Web.UI.MobileControls.MobilePage
    {
           protected System.Web.UI.MobileControls.Command Command2;
           protected System.Web.UI.MobileControls.TextBox TextBox1;
          
    protected System.Web.UI.MobileControls.Link Link1;
          
    protected System.Web.UI.MobileControls.Label Label1;
          
    protected System.Web.UI.MobileControls.Label Label2;
          
    protected System.Web.UI.MobileControls.Form Form1;

           private void Page_Load(object sender, System.EventArgs e)
           {
                   
    if (Request.Params["ID"] != null) // Works
                   
    {
                         Label2.Text = "ID=" + Request.Params["ID"];
                    }
                   
    if (TextBox1.Text.Length > 0) // Only works when the button is clicked
                   
    {
                         Label1.Text = "You typed:" + TextBox1.Text;
                    }
            }
    }
     
    <body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">
     <mobile:form id="Form1" runat="server">
      <mobile:TextBox id="TextBox1" runat="server"></mobile:TextBox>
      <mobile:Command id="Command2" runat="server" Format="Link">Button as link</mobile:Command>
      <mobile:Link id="Link1" runat="server" NavigateUrl="Test.aspx?ID=100">Link</mobile:Link>
      <mobile:Label id="Label1" runat="server"></mobile:Label>
      <mobile:Label id="Label2" runat="server"></mobile:Label>
     </mobile:form>
    </body>






     

    Wednesday, August 3, 2005 2:29 AM
  • User-1361599924 posted
    Whoops! My sample code worked because I had entered a value for the textbox at design time.
    I've stopped being silly now and I have your answer.

    You can use this method to kick off behaviours on your form, but you cannot use it to send data back to a form like a true postback would. Your textbox is empty because it's new value is never being posted back to the web server. In my commercial mobile web application, we make entensive used of links as detailed in these postings, however if we need to send data back from webform to web application we use a button that looks like a button!

    So, there you have the major drawback. I should have remembered that somewhat earlier!! Apologies.
    Wednesday, August 3, 2005 9:17 AM
  • User-2115551320 posted
    OK, just as I thought. Thanks for your reply!

    Nicholas
    Thursday, August 4, 2005 1:29 AM