Detect current device channel from code behind

From
MSDN article about device channels:
Also, device channels can set a JavaScript variable called effectiveDeviceChannel that contains the current channel alias. This variable can be used to show which channel is currently being used.
Is there similar variable, that could be used in code behind (in C#), to determine which channel is currently used?

You can use DeviceChannelPanel in your web part...
For e.g. the following in a visual web part will render only to a channel that is targetted for tablets.
<Publishing:DeviceChannelPanel runat="server" ID="pnlTab" IncludedChannels="Tab">
    You can see this tab devices.
</Publishing:DeviceChannelPanel>
From code behind, you can create a device channel panel dynamically and add contents to it.
e.g.
            LiteralControl l = new LiteralControl();
            l.Text += "Sample content for tablets";
            DeviceChannelPanel dp = new DeviceChannelPanel();
            dp.Controls.Add(l);
            dp.IncludedChannels = "Tab";
            MyPanel.Controls.Add(dp);

Similar Messages

  • Updating a Label content from code behind using dispatcher

    hi,
    I am trying to update a label's content from code behind.
    This part of the code is running in background worker. I wrote the following code to update a label's content:
    volumecontrol.Dispatcher.BeginInvoke(new Action(() =>
    volumecontrol.Content = volumeupdate;
     i tried using both BeginInvoke and Invoke but the application exits with the error:
    System.InvalidOperationException' occurred in WindowsBase.dll
    Using Invoke works when updating the UI from another thread but it not working in this case:
    Pls help.
    Thanks,
    Shaleen
    TheHexLord

    When you do that new action stuff you're capturing variables.
    If that means you grab a control's value across from outside the {} then you're trying to capture the variable on the background thread.  If that's some sort of control you're messing with then that will cause a problem as they have thread affinity.
    Because you don't want to be blocking the UI thread at all you should use BeginInvoke rather than Invoke.
    To explain this clearly - and provide a way you could use to explore what's going on and learn  - we need a separate thread which can be done using Task.Factory.StartNew.
    This bit of code allows you to put code onto a background thread:
    Task.Factory.StartNew(() =>
    // On a separate thread to the UI here
    Create a new solution, add a textBlock and Button:
    <StackPanel>
    <TextBlock Name="tb"/>
    <Button Name="btn" Click="btn_Click">Change the text</Button>
    </StackPanel>
    Then in the button click you can play around with what's going on.
    Just to be clear.
    That textblock is a control and it is created on the UI thread.
    To get from that task thread back to the UI thread you should use Dispatcher.BeginInvoke.  With no control name.
    Let's start with a broken piece of code:
    private void btn_Click(object sender, RoutedEventArgs e)
    Task.Factory.StartNew(() =>
    string thingummy = tb.Text + "Banana";
    Dispatcher.BeginInvoke(new Action(() => { tb.Text = thingummy; }));
    When you click the button it'll error because when you access tb.Text there you do so on a background thread and tb has thread affinity.
    This, however, will work OK.
    Task.Factory.StartNew(() =>
    Dispatcher.BeginInvoke(new Action(() => { tb.Text = tb.Text + "Banana"; }));
    That's OK because the Action runs on the UI thread where tb was created and all is good.
    Anonymous methods and actions capture variables ( you can google that for more info ).
    If you wanted to use a variable which was created on the background thread you can set it here:
    Task.Factory.StartNew(() =>
    string thingummy = "banana";
    Dispatcher.BeginInvoke(new Action(() => { tb.Text = thingummy; }));
    or here
    string thingummy = "banana";
    Task.Factory.StartNew(() =>
    Dispatcher.BeginInvoke(new Action(() => { tb.Text = thingummy; }));
    They both work.
    They are not accessing properties of a UI control because you're just setting the variable to a string.
    All of which means you could have a variable in your code which is set to volume or whatever that is from your control  ON THE UI THREAD and then modify that variable on the background thread.  Variables do not have thread affinity.  A
    double, string or whatever isn't a control.
    And this approach might well be more convenient.
    Hope that helps.
    Recent Technet articles:
    Property List Editing ;  
    Dynamic XAML

  • [WPF] AutoCompleteBox: set parameters from code behind

    Hi,
    I'm using AutoCompleteBox from Codeplex.com
    I would set some parameters from code behind... 
    In XAML, I defined namespace:
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
    After using AutoCompleteBox:
    <toolkit:AutoCompleteBox
    x:Name="myAutoComplete"
    ItemsSource="{Binding Source={StaticResource DomainDataViewModel}, Path=SampleProperties, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
    SelectedItem="{Binding Name}"
    ValueMemberPath="Name"
    ItemTemplate="{StaticResource PropertyBoxItemTemplate}"
    MouseLeave="PropertyAutoCompleteBox_MouseLeave"
    >
    </toolkit:AutoCompleteBox>
    If I would set any parameter from code behind, in my.xaml.cs, I not found myAutoComplete, why?
    Thanks.

    >>I inserted the AutoCompleteBox as DataGridTemplateColumn.CellEditingTemplate.
    Then you cannot access it directly from the code-behind as I told you.
    >>I would apply a FilterCustom and a ItemFilter.
    You could handle the Loaded event for the AutoCompleteBox and set any of its properties in there:
    <toolkit:AutoCompleteBox
    x:Name="myAutoComplete"
    Loaded="myAutoComplete_Loaded"
    ItemsSource="{Binding Source={StaticResource DomainDataViewModel}, Path=SampleProperties, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
    SelectedItem="{Binding Name}"
    ValueMemberPath="Name"
    ItemTemplate="{StaticResource PropertyBoxItemTemplate}"
    MouseLeave="PropertyAutoCompleteBox_MouseLeave"
    >
    </toolkit:AutoCompleteBox>
    private void myAutoComplete_Loaded(object sender, RoutedEventArgs e)
    AutoCompleteBox myAutoComplete = sender as AutoCompleteBox;
    //set properties or do whatever here...
    myAutoComplete.ValueMemberPath = "Name";
    dynamic dataObject = myAutoComplete.DataContext;
    //access any properies of the data object in the DataGrid...
    How to do filtering is a completely other question that should be asked in a new thread though. It has nothing to do with your original question.
    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

  • Setting JSLink for XSLTListViewWebPart from code behind

    I am adding an XSLTListViewWebPart from within a user contol code behind.  It adds fine, but I am not able to get it to resolve the JSLink file.  The js file works, as I've attached it to a list view web part in the web part properties and it works.
    How do I set the JSLink property from the code?  I have set it on the view object and on the XsltListViewWebPart, but neither has any effect.  This has to be deployable from a wsp, so setting the value from the UI is not an option. 
    XsltListViewWebPart FooterMenuListView = new XsltListViewWebPart();
      FooterMenuListView.ListId = linkList.ID;
      FooterMenuListView.ViewGuid = linkView.ID.ToString("B");
      FooterMenuListView.JSLink = "/_Layouts/15/FooterMenu.js";                                
      FooterMenuListView.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
      FooterMenuListView.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;
      phFooterMenuList.Controls.Add(FooterMenuListView);
    Any advice would be appreciated.

    Hi,
    Please try to use the code line below:
    FooterMenuListView.JSLink = "/_layouts/15/FooterMenu.js";
    Or you can upload the js file into a document library(JSLib) and use like this:
    FooterMenuListView.JSLink = "~site/JSLib/FooterMenu.js";
    JSLink also supports the following tokens, you can try it.
    •~site
    •~sitecollection
    •~layouts
    •~siteLayouts
    •~siteCollectionLayouts
    More information:
    http://spdevlab.com/2013/07/07/5-facts-about-jslink-in-sharepoint-2013-you-might-not-know/
    http://networkedblogs.com/GmSvo
    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Dennis Guo
    TechNet Community Support

  • Raiseevent from code behind

    I need to use the PCC to update a secondary portlet at a specific time during the postback of a click event. Can I use the PCC to raise an event from the code behind file?

    I'm afraid you cannot do this - the PCC exists solely on the client so must be called from the client, not the server. What you can do is include some javascript to handle this instead. One simple solution would be to add the script block
    <script defer language="JavaScript">document.PCC.raiseEvent(...)</script>
    This however will only work in IE. If you want cross browser support then you will have to register for your own portlets rerender event, then upon a rerender you must check some condition which you set in the codebehind (i.e. the text in a hidden element) and raise the PCC event accordingly.

  • Newbie: Trying to get data  from Code Behind file to HTML file.

    Greetings,
    I am trying to use the opener link adaptive tag to open a specific page. I have the Object ID, and classID as variables in my class in my class file, but I do not know how to get that data into the opener link which is on the html page.
    Should I be using session variables? If so how, I am a newbie.
    Does anyone know how?
    Thanks.

    Kinda depends on your flavor/need/preference. I've done it...
    * Using session variables and just writing to the page in script blocks. Not preferred in .NET-land, but definitely more of the fast/traditional ASP style. Use sparingly and with caution. Be really careful about VS.NET totally destroying your tags. It seems to love doing that (as an aside - HUGE thank-yous to the BEA engineers who altered the tags to consistenly use lower case. Really. I can't thank you enough. :) )
    * Using label controls and then just populating the label with the formatted adaptive tag (this can work well)
    * One of our guys did a really simple/elegant server control that takes arguments for the objectid, classid, etc. Nice for creating things repeatedly server-side and gets you by the HTML, quotes, etc. all over the place. Nice as it also consolidates the tag in a single place you can alter once.
    For session variables, you'd just do something like...
    <%
    '//in your code-behind
    Session("myClassID") = 18
    Session("myObjectID") = 12345
    %>
    <!-- in your aspx file -->
    <pt:standard.openerlink xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' pt:objectid='<%=Session("myObjectID")%>' pt:classid='<%=Session("myClassID")%>' pt:mode='2' target='myWindow' onclick=window.top.open('','myWindow','height=800,width=700,status=no,toolbar=no,menubar=no, location=no');>Adaptive Tags Made This Easy - Click to Open My Awesome Document</pt:standard.openerlink>
    That help?
    Personal style, I would try to avoid using session, etc. directly on your ASPX file. I'd go with writing out the HTML through labels, data lists, etc. in your code-behind.
    Thanks,
    Eric

  • How To Force Open Document In Edit Mode From Code-Behind (Chrome and Firefox)?

    Hello,
    Currently I am developing an IHttpHandler which at the should redirect the user to an Edit mode of a document located in a Document Library.
    The Problem is that in Firefox and Chrome it downloads the document in the temp folder. In IE it works as expected.
    The following code is used for the redirection:
    SPUtility.Redirect(urlOfTheNewDocument, SPRedirectFlags.Trusted, context);

    Hi,
    Please try to use IE Tab.
    Chrome IE Tab:
    https://chrome.google.com/webstore/detail/ie-tab/hehijbfgiekmjfkfjpbkbammjbdenadd?hl=en 
    Firefox IE Tab:
    https://addons.mozilla.org/en-us/firefox/addon/ie-tab/
    Here is a similar thread for your reference:
    http://stackoverflow.com/questions/14455212/how-to-open-sharepoint-files-in-chrome-firefox
    Thanks,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Dennis Guo
    TechNet Community Support

  • How to Get Resource value which are referred in code behind file using IResourceProvider

    Hi Everyone,
    Currently I'm working on moving the Resource file from "App_GlobalResources" to Database by using IResourceProvider. I created a CustomResourceProvider project using ResourceProviderFactory and able to get the resource values from DB which
    are used in aspx page.
    But i'm not able to get the values which are referring from code behind file.
    Ex: Label1.Text = Resources.Common.Car; // This is still coming from resx file.
    Can any one please let me know how to get the value from DB instead of resx file which are referred in cs file.
    Appreciate your help. 
    The below code uses the ResourceProviderFactory which calls this method and gets it from DB. Please let me know if you need any more info.
    public class DBResourceProviderFactory : ResourceProviderFactory
            public override IResourceProvider CreateGlobalResourceProvider(string classKey)
                return new DBResourceProvider(classKey);
            public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
                 // we should always get a path from the runtime
                string classKey = virtualPath;
                if (!string.IsNullOrEmpty(virtualPath))
                    virtualPath = virtualPath.Remove(0, 1);
                    classKey = virtualPath.Remove(0, virtualPath.IndexOf('/') + 1);
                return new DBResourceProvider(classKey);
    Regards, Ravi Neelam.

    Hi Ravi Neelam.
    >>Currently I'm working on moving the Resource file from "App_GlobalResources" to Database by using IResourceProvider.
    Based on this message, your issue related to web application, questions related to Asp.Net should be posted in
    Asp.Net forum.
    Please reopen a new thread in that forum. You will get more efficient response.
    Regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to execute SQL Query in Code behind Using infopath 2010?

    Hi,
    I've repeatable on infopath form, and want bind it throuth code behind from SQL table. My question is that how to execute SQL Query in code behind from infopath as well as how would get Query result to bind repeatable control?
    Thanks In Advance
    Shoeb Ahmad

    Hello,
    You first need to add new SQL DB connection then you need execute connection from code behind.
    See below link to create new connection
    http://office.microsoft.com/en-in/infopath-help/add-a-data-connection-to-a-microsoft-sql-server-database-HP010092823.aspx:
    http://www.bizsupportonline.net/infopath2010/connect-infopath-2010-sql-server-2008-table.htm
    Then use below code to execute this connection:
    AdoQueryConnection conn = (AdoQueryConnection)(this.DataConnections["Data connection name"]);
    string origCommand = Select * from tablename;
    conn.Command = origCommand;
    conn.Execute();
    Finally bind your table:
    http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
    http://stevemannspath.blogspot.in/2010/09/infopath-20072010-populate-repeating.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to call "detect capture devices" in my program

    Hi,
    I'd like to develop a webcam program. Is it possible to call jmfregistry's "Detect Capture Devices" in my code? So I don't have to ask the user run jmfregistry.
    Thanks,
    Derek

    detect capture devices is dependent of the plataform. I recommend to look into the source code of JMFRegistry and JMF.

  • Error Message in Code Behind Visual Web Part

    I want to show validation message in code behing when i click submit button,below is my code
    <asp:TextBox ID="txtBoxName" runat="server" Width="50%"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvCompanyName" ControlToValidate="txtBoxName"
    ValidationGroup="RegistrationGrp" SetFocusOnError="True" runat="server" Text="*" ErrorMessage="Please Enter Name"></asp:RequiredFieldValidator>
    protected void btnSubmit_Click(object sender, EventArgs e)
    i want to show this error message "Please enter name"
    from code behind,how do i do that??

    I am inserting item from the input textbox in the sharepoint list in submit button like below,so i did what u suggested in that click event
    protected void btnSubmit_Click(object sender, EventArgs e)
                   if (!Page.IsValid)
                        rfvCompanyName.ErrorMessage = "test test";
                        return;
                        using (SPWeb web = site.OpenWeb())
                            SPList list = web.Lists["Company Details"];
                            SPListItem item = list.Items.Add();
                            item["Title"] = txtBoxName.Text;
                            item.Update();
    but it's not showing this message,please suggest what i am missing

  • Device Channels neither working on SharePoint Online nor OnPrem

    I already posted this issue on Office365 forum but considering the urgency of the task I am posting this issues over here  as well.
    Its about device channels and setting up device channels requires very simple configurations but unfortunately I couldnt make it work.On the SharePoint Online I followed the procedure as give
    below:
    1. Created a copy of Seatle Master page using SharePoint 2013 designer and added some text in it body to make it little different from the original seatle (I  checked it in and published it and verified that it works).
    2. Then created a  device channel from the SharePoint Online Site setting and  provided the Name of the Device channel i.e. "MobileDevices", Alias, Description, Device Inclusion rules for Windows Phone 8 as follows:
    Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920
    Also tried the following separately:
    Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone OS 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 1520
    and then:
    Android
    $FALLBACKMOBILEUSERAGENTS;
    Windows Phone
    3. To get Master pages setting, activated the "SharePoint Server publishing feature" from both Site features and Site collection features.
    4. On the Master page settings page, I set my custom master page for the device channel that  I already created.I also tried Oslo here and also tried oslo in Default
    To test that I browsed the site with the query string:
    https://Company.sharepoint.com/teams/default.aspx?DeviceChannel=MobileDevices
    and also used the Internet Explorer's emulator for windows phone 8 but unfortunately this did not work and the right master page did not show up.
    I also used my Android device here but the right master page appear. 
    Moreover I also deactivated the "Wiki Page Home Page" feature. Furthermore I tried doing the same on my SharePoint 2013
    Dev VM (Local single server farm) but to no avail. 
    The problem seems like there is some issue with switching to the right master page or the device is not recognized. May
    be I am missing so configuration. I would really appreciate if anyone could assist me in solving this issues 
    If you need any further info, I will happily provide that.
    Resources: 
    http://social.technet.microsoft.com/wiki/contents/articles/23157.sharepoint-2013-device-channels.aspx
    http://www.dotnetspark.com/kb/5971-device-channels-sharepoint-2013.aspx
    http://blog.mastykarz.nl/device-channels-sharepoint-2013/

    Hi Vhyder,
    I have seen the thread that you posted in Office 365 forum, the thread is answered.
    The solution is creating a Publishing site  instead of creating a team site and activating the publishing features.
    The thread is:
    http://community.office365.com/en-us/f/173/t/343224.aspx
    As your issue is solved, I will mark the reply as anwser to close this case.
    Best Regards,
    Wendy
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • HT4914 My wife and I both have iPhones and iPads. Can we both have access to the same iTunes Match library or do we have to have separate subscriptions?  Our devices are synced to the same computer and we currently download titles from the same library.

    My wife and I both have iPhones and iPads. Can we both have access to the same iTunes Match library or do we have to have separate subscriptions?  Our devices are synced to the same computer and we currently download titles from the same library.  We both use separate apple id's on our devices.

    You need to reconfigure your phone for use with your Apple ID. I suggest you restore yours as new then reconfigure it with your information and Apple ID. Be sure to disable Find My Phone, if it's enabled, before proceeding.
    Locked Out, Forgot Lock or Restrictions Passcode, or Need to Restore Your Device: Several Alternative Solutions
    A
    1. iOS- Forgotten passcode or device disabled after entering wrong passcode
    2. iPhone, iPad, iPod touch: Wrong passcode results in red disabled screen
    3. Restoring iPod touch after forgotten passcode
    4. What to Do If You've Forgotten Your iPhone's Passcode
    5. iOS- Understanding passcodes
    6. iTunes 10 for Mac- Update and restore software on iPod, iPhone, or iPad
    7. iOS - Unable to update or restore
    Forgotten Restrictions Passcode Help
                iPad,iPod,iPod Touch Recovery Mode
    You will need to restore your device as New to remove a Restrictions passcode. Go through the normal process to restore your device, but when you see the options to restore as New or from a backup, be sure to choose New.
    You can restore from a backup if you have one from BEFORE you set the restrictions passcode.
    Also, see iTunes- Restoring iOS software.

  • HT1766 How can I view the content of an iCloud backup of a previous device?  I have two backups showing in iCloud, one for my current device and one for a previous device.  I would like to review the content from the prior device and possibly consolidate

    I want to review content in a backup from a previous iOS device to decide whether to delete the backup from iCloud. I'm most concerned about keeping photos I took on the previous phone. Ideally, I would consolidate the photos to my current device and have just one backup in iCloud.
    My current device is a iPhone 5s running 7.0.6, and my prior device was an iPhone 5.  Not sure what version of iOS I was running, but last backup on that phone was march 2013.

    You cannot review a backup. You can only restore it to a device. You can see here what is backed up:
    iCloud: http://support.apple.com/kb/PH12519
    iTunes: http://support.apple.com/kb/ht4946

  • How to call a Web Api from from a Visual webpart code behind?

    Hi,
    I am trying to create a visual web part in sharepoint 2013 with data received from another Web API.
    I followed the below steps.
    1. Created a Visual Web part.
    2. In the code behind(.cs) file I wrote the following code.
     async private void GetResult()
                using (var client = new HttpClient())
                    client.BaseAddress = new Uri("http://localhost:8080/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var response = await client.GetAsync("api/Tfs/OpenEnquiriesCount");
                    var content = response.Content;
    3. When I run the application, I get security exception in the line await
    client.GetAsync()
    What is the way to achieve this? How to call a web api from share point visual web part?
    Thank you in advance.

    Hi,
    Thanks for your sharing.
    Cheers,
    Jason
    Jason Guo
    TechNet Community Support

Maybe you are looking for

  • New 2012 R2 domain - xp clients cannot join or print

    I just migrated a 2003  domain to 2012 R2.   Things were working ok & then XP clients became AD stupid. Steps I took: Added a VM 2012 R2 DC to the domain.  Server had DNS installed.  Ran dcdiag & bpa and resolved any issues.  About a week later I mov

  • Acceptance of EULA before opening a PDF document

    I cannot open a PDf document The message that appears Accept end user licence agreement and then re open

  • Record to Desktop in Premiere / OnLocation MIA?

    With the CS5 suite I was able to use OnLocation to capture video via a connected camcorder.  And that was super.  However, OnLocation seems to be missing in CS6.  Has it been retired or is there a replacement or updated feature in Premiere that takes

  • Using kodak C360 with Iphoto

    Has anyone used the Kodak C360 with Iphoto? The camera is not on the "approved" apple list, but it seems some people in the discussions have still had luck with some cameras working. Thanks

  • Safari isn't working on a lot of websites, is it out of date?

    Certain websites I visit won't work properly using Safari, some video on Yahoo won't work either have to use Mozilla, but don't like Mozilla, and i'm getting a message on some sites telling me my browser is out of date. When I check software updates