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.

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.

  • 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);

  • 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

  • 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

  • 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

  • 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

  • Assign Tabitem Style from xaml in Code behind

    Hi
    I have a style defined for TabItem in XAML.
    I am generating the TabItem Dynamically and i want to add the Style create from XAML to the tabitem that is created dynamicaly.
    Here is my XAML code
    <TabControl Name="tc" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="White">
    <TabControl.Resources>
    <Style TargetType="TabItem" x:Key="hi">
    <Setter Property="VerticalAlignment" Value="Bottom" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type TabItem}">
    <Grid>
    <Border Name="Border" Background="LightBlue" BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="2,12,12,2" > <ContentPresenter x:Name="ContentSite"
    VerticalAlignment="Center"
    HorizontalAlignment="Center"
    ContentSource="Header"
    Margin="12,2,12,2"/>
    </Border>
    </Grid>
    <ControlTemplate.Triggers>
    <Trigger Property="IsSelected" Value="True">
    <Setter TargetName="Border" Property="Background" Value="LightSkyBlue" />
    </Trigger>
    <Trigger Property="IsSelected" Value="False">
    <Setter TargetName="Border" Property="Background" Value="GhostWhite" />
    </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </TabControl.Resources>
    </TabControl
    in code behind i am trying to assign the style
    private void example_Click_1(object sender, RoutedEventArgs e)
    try
    ExampleGrid ex = new ExampleGrid();
    Close_Tab theTabItem = new Close_Tab();
    theTabItem.Title = "my Grid";
    tc.Items.Add(theTabItem);
    theTabItem.Style = (Style)FindResource("hi");
    theTabItem.Content = ex;
    theTabItem.Focus();
    catch (Exception ee)
    MessageBox.Show(ee.Message);
    I am getting an exception saying resource hi is not found
    Note: hi is the name of the style.
    Please suggest me the solution for this.
    Thanks All

    I believe if you remove x:key attribute from the tab style
    <Style TargetType="TabItem"> ... </Style>
    then it will be applied to all tabs.
    If this not works then take out your style definition from <TabControl.Resources> and put it the resource of parent control which contains TabControl
    e.g
    <UserControl ...>
    <UserControl.Resources>
    <Style TargetType="TabItem"> ... </Style> // don't add x:key attribute
    </UserControl.Resources>
    <TabControl> .. </TabControl>
    </UserControl>

  • "Object Required" error when using the script block from the code behind

    I try to use the following script block on the code behind page
    <script defer='true' id='NavID' type='text/javascript'>Nav();</script>
    and the function Nav() is on the .aspx page. It gives me the "Object Required" error message. BUT if I add an alert("hello!!!") line inside of the Nav() function, it works fine after the user closes the alert box. Has anyone experienced a similar problem? Please help. Thanks.

    There is no way to troubleshoot this by looking at a picture of the diagram. LabVIEW 6 is almost prehistory and many things have changed, especially the file IO all looks different so it is impossible to tell what you are doing.
    Error 7 is file not found, so most likely your string operations are not correct. What are the full strings? What is the final file name (maybe you are missing a "\" or maybe you are on a different OS type). Put an indicator at the path wire to see what's happening!
    Is this a datalog file?
    (Overall, the code is a bit suspect. Nobody needs a seven frame flat sequence. ) Why do a control and an indicator have the same label?)
    LabVIEW Champion . Do more with less code and in less time .

  • Error for visual ADF from xml code behind

    Hello all:
    I am a freshman to use Jdeveloper 10.1.3.1.
    When I was using faces-config.xml to create JSP and JSPX page, the ADF component control suddenly diplayed abnormally, Only to show the tagbox like form, html, head, body and so on in Design view, sometimes even nothing to display,.But when I restart jdeveloper, some page would be OK again, others still can not be show normally. I checked the code behind the page.there is nothing wrong, because these codes are all auto-created.
    Thanks to advance
    Bonnie([email protected])

    I have solved this problem.
    Because I added a filter into web.xml. It seemed that this would be complied while in design model. After I removed it, it's OK!

  • Customize Access Requried page with code behind attached to it in sharepoint 2010

    Hi,
    I have modified default AccessDenied page to my custom accessdenied.aspx page and put Request Access button on it and javascript client side redirection to my requestaccess (reqestaccess.aspx, reqestaccess.aspx.cs) application page.
    Here the problem is whenever i try to redirect to custom requesaccess page in _layouts it again shows me accessdenied page since user is not having access.
    I changed requrestaccess to my custom requestaccess through Powershell command (UpdateMapping - 5). I can only modify the UI part of requestaccess.aspx and can not bind code behind where i want user to select combination of what access is required
    on the site, there are lots of controls on requestaccess page e.g. dropdown that fetches data from list\external list and so on.
    I tried many things to attach code behind to requestaccess page e.g. <%@ Page Inherits="codebehind.cs" /> and all.
    Q - How can i redirect user to custom request access page (includes both aspx, aspx.cs) and allow user to interact with custom page? Is there any way OR WORKAROUND to do this in Sharepoint 2010?
    OR
    Can we overide with ElevetedPermissions in UI\CodeBehind and show the application page to user?
    OR
    Can user access application page even though they donot have rights to access site? Anything will do.
    OR
    In short, I need to redirect a user to some .aspx\.aspx.cs page from AccessDenied page, irrespective of user having access or not. 
    I hope question is clear enough to understand the issue. :)
    Regards,
    Rahul

    Hi,
    According to your post, my understanding is that you had an issue about the custom Access Required page.
    Microsoft supported using code behind, but for these pages it seemed some difference.
    However, as a workaround, we can put all the functionality to the aspx page directly.
    http://umbraes-tower.blogspot.com/2011/10/custom-request-access-page-in.html
    More reference:
    http://onlinecoder.blogspot.com/2011/05/how-to-customize-requestaccess.html
    http://oszakiewski.net/eric/customizing-the-access-request-page-in-sharepoint-2010
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

Maybe you are looking for