This section provides tips, tricks, and best practices for using Studio for iPhone controls.
• When you make a navigation list visible, you should call the Invalidate method in order to ensure that some specific item types have invalidated correctly. For instance, if your navigation list has a C1NavigationListSliderItem or a C1NavigationListInputItem, you will need to add the call the Invalidate method as in the following example:
function onClientClick_List1() {
var navList1 =
Sys.Application.findComponent("<%=List1.ClientID%>");
navList1.set_displayVisible(true);
// Invalidate all currently visible items
navList1.invalidate();
viewPort.scrollContentToOrigin();
}
• When you design your Web site or application, keep in mind the display metrics of the iPhone browser. To learn more, see Safari Layout on the iPhone.
• You can create a confirm dialog box using JavaScript. For task-based help about creating a confirm dialog box, see Creating a Confirm Dialog Box.
• For a performance boost, try to avoid full-page postbacks whenever possible. You can prevent full postbacks using Studio for iPhone's client-side object model. Below are a few examples that illustrate how to avoid postbacks:
o You can access Studio for iPhone controls on the client-side, such as in the following example:
var navList = $find("<%=C1NavigationList1.ClientID%>");
o You can execute client-side code upon Web application load, as in the following example:
Sys.Application.add_load(function() {
// some code goes here
});
o You can create a Web service and population the C1NavigationList on the client side, such as the following example:
a. Right click the Web site root node and select Add New Item.
b. Select Web Service (the default name will be WebService.asmx), set the language to C#, and then click Add.
c. Open WebService.cs and uncomment the InitializeComponent() method.
d. Define the Web methods, for example:
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
}
[WebMethod]
public List<SampleRecord> GetRecords(string parameter)
{
List<SampleRecord> list = new List<SampleRecord>();
list.Add(new SampleRecord("Title 1 " + parameter, "Note 1"));
list.Add(new SampleRecord("Title 2 " + parameter, "Note 2"));
list.Add(new SampleRecord("Title 3 " + parameter, "Note 3"));
return list;
}
}
public class SampleRecord
{
private string _title;
private string _note;
public SampleRecord(string title, string note)
{
this._title = title; this._note = note;
}
public string Title
{
get{return _title;}
set{_title = value;}
}
public string Note
{
get{return _note;}
set{_note = value;}
}
}
e. Open the project's .aspx page.
f. Register the Web service within the ScriptManager control:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService.asmx" />
</Services>
</asp:ScriptManager>
g. Access the Web service from client code and populate the navigation list (note, the LoadOnDemand property of the C1NavigationList must be set to False):
<C1ViewPort:C1ViewPort ID="C1ViewPort1" runat="server">
<Content>
<cc1:C1NavigationList ID="C1NavigationList1" runat="server" LoadOnDemand="false">
</cc1:C1NavigationList>
</Content>
</C1ViewPort:C1ViewPort>
<script type="text/javascript">
/* called when webservice method failed */
function webserviceFail(err) {
alert("Call to webservice failed: " + err.get_message());
}
// ***** GetRecords web service results callback *****
function GetRecordsCallback(results) {
var navList = $find("<%=C1NavigationList1.ClientID%>");
// get items collection
var items = navList.get_items();
// Clear all items from collection:
items.clear();
// Populate navigation list:
var count = results.length;
for (var i = 0; i < count; i++) {
var record = results[i];
// get title and note for current record:
var title = record.Title
var note = record.Note
// Create new item dynamically:
var newItem = new C1.Web.iPhone.C1NavigationList.C1NavigationListInputItem();
items.add(newItem);
newItem.set_text(title);
newItem.set_bottomText(note);
}
}
Sys.Application.add_load(function() {
// Call GetRecords method of the WebService:
WebService.GetRecords("my parameter", GetRecordsCallback, webserviceFail, null);
});
</script>
o You can create navigation list items on the client side, as in the following example:
var navList = $find("<%=C1NavigationList1.ClientID%>");
// Add list item:
var newItem = new C1.Web.iPhone.C1NavigationList.C1NavigationListItem();
navList.get_items().add(newItem);
newItem.set_text("text");
newItem.set_detailText("detailText");
newItem.set_topText("topText");
newItem.set_bottomText("bottomText");
// Add link item:
var newItem = new C1.Web.iPhone.C1NavigationList.C1NavigationListLinkItem();
navList.get_items().add(newItem);
newItem.set_text("Link");
newItem.set_navigateUrl("Link");
// Add input item:
var newItem = new C1.Web.iPhone.C1NavigationList.C1NavigationListInputItem();
navList.get_items().add(newItem);
newItem.set_text("Text");
newItem.set_value("value");
// Add switch item:
var newItem = new C1.Web.iPhone.C1NavigationList.C1NavigationListSwitchItem();
navList.get_items().add(newItem);
newItem.set_checked(isChecked);
newItem.set_text("Switch");
o You can access navigation list items on the client side, such as in the following examples:
•Using the navigation list item's
index
var navList = $find("<%=C1NavigationList1.ClientID%>");
// using item's index:
var item1 = navList.get_items().get_item(0);
var item2 = navList.get_items().get_item(1);
•Using the navigation list item's command
code
XML Markup:
<cc1:C1NavigationListButtonItem runat="server" Text="Submit" CommandName="CommandNameValue"></cc1:C1NavigationListButtonItem>
JavaScript:
var item3 = navList.findItemByCommandName("CommandNameValue");
•Using the navigation list item's command
argument
XML Markup:
<cc1:C1NavigationListItem runat="server" Text="Submit" CommandArgument="CommandNameArgumentValue"></cc1:C1NavigationListItem>
JavaScript:
var item3 = navList.findItemByCommandArgument("CommandNameArgumentValue");
•Using the navigation list item's
text
XML Markup:
<cc1:C1NavigationListItem runat="server" Text="Submit"></cc1:C1NavigationListItem>
JavaScript:
var item3 = navList.findItemByText("Submit");