locked
Calling Javascript Function From Mobile Forms Page RRS feed

  • Question

  • User-249004326 posted

    I have an application that needs to call a JavaScript function from within an aspx MobileForms page to access GPS information on a BlackBerry device.  I can get the function to work with just a simple HTML file using an Input button to call the script.  However, I can't find how to do the same from within a MobileForms page.  I understand how to insert the JavaScript with the <ScriptTemplate> tag, but I don't know how to hook this function up to an event or control to call the function.  It seems that the Input button is not supported in MobileForms and the mobile Command button runs at the server.  Can anyone tell me how to hook up the JavaScript function to a control with a Click event?

    Thanks

    Larry

    Thursday, October 12, 2006 2:08 PM

All replies

  • User-1692070805 posted
    I have used Javascript in mobile forms on the Blackberry, but I don't think I have had it post back anything to the server if that is what you need. 

     

    For example, I have an application that puts out 5 radio buttons and based on which one is clicked, it populates a TextBox field.  It does that entirely within Javascript and does not post anything back to the server, so I'm not sure if that's equivalent to what you want to do.

     

    But I did it like this:

     

    In the form:

    <mobile:DeviceSpecific id="devHistory" runat="server">
    	<Choice>
    		<FooterTemplate>
    			<asp:Literal runat="server" id="lblHistoryData"></asp:Literal>
    		</FooterTemplate>
    	</Choice>
    </mobile:DeviceSpecific>
    

    In the code behind in the Form's Activate event:

    StringBuilder histList = new StringBuilder();
    histList.Append("<input type=radio name=\"history\" value=\"value1\" onclick=\"document.QueryForm.txtCompany.value='value1'\">Value 1</input><br/>");
    histList.Append("<input type=radio name=\"history\" value=\"value2\" onclick=\"document.QueryForm.txtCompany.value='value2'\">Value 2</input><br/>");
    ...
    System.Web.UI.WebControls.Literal lblTemplateHistoryData = (System.Web.UI.WebControls.Literal)this.QueryForm.Footer.FindControl("lblHistoryData");
    lblTemplateHistoryData.Text = histList.ToString();
    What this does is finds the asp:Literal control (embedded in the form footer in my case) and replaces it with Javascript dynamically built in a string.
    It sets up an onclick Javascript event for each radio button, which uses DOM to populate another field on the form.  You could probably use a similar technique that would create some other clickable control that would call the GPS function and put the value returned into a server TextBox, which would then get sent back to the server when the form was submitted.
    That may be less than ideal - if you wanted it to do that and then automatically submit the form, you would have to see if the Blackberry allows you to programatically submit the form with Javascript.
    Or you could see if you could call .click() on the submit button on the form.
    (I seemed to find that every time I wanted to do something in Javascript, there was something the Blackberry didn't support.)
    
    Tuesday, October 17, 2006 10:48 PM