Pages

Showing posts with label content. Show all posts
Showing posts with label content. Show all posts

Saturday, August 16, 2014

How To: Load SharePoint web part User Control Inside another SharePoint web part without C# Coding

simple way to Load SharePoint web part User Control Inside another  SharePoint web part without C# Coding is done by :

  1. registering the user control
    <%@ Register src="webPartUC.ascx" tagname="webPartUC" tagprefix="uc" %>

  2. loading the user control <uc:webPartUC ID="webPartUC1" runat="server" />
if you wanted to pass webpart properties.. all you have to do is to specify the values as follows:
<uc:webPartUC ID="webPartUC1" LabelText="TEXT" runat="server" />

if you wanted to pass webpart properties from within a DataList Control Items .. all you have to do is to specify the values as follows making sure to add the below line inside the DataList:

 <asp:DataList ID="usersDL" runat="server" Width="100%" >
   <ItemTemplate>
         <uc:webPartUC ID="webPartUC1"
              LabelText=<%# Eval("userName")%> runat="server" />

    </ItemTemplate>
 </asp:DataList>


Thats it :)

    

Tuesday, September 3, 2013

Passing url parameters to webpart in SharePoint

To pass the URL parameters to a webpart page in SharePoint, we can't use the "Page Viewer" webpart because it does not allow us to use the parameters in the URL.

So we use teh "Content Editor" webpart since it allows us to embed javascript code in it. We can then use an "iframe" with a generated URL from a JavaScript with URL parameters from the webpart page's URL.

First, create a webpart page, then insert a content editor webpart in it with the following code:
<script type="text/javascript">
    function getQueryStringRegExp(name) {
        var reg = new RegExp("(^|\\?|&)"
+ name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(location.href))
return unescape(RegExp.$2.replace(/\+/g, " "));
        return "";
    }
    document.write("<iframe src='http://www.sitename.com/default.aspx?param1="+ getQueryStringRegExp('param1') + "' width=100% height=100%></iframe>");
</script>

The function getQueryStringRegExp is used to retrieve the parameter value from the page url.

Referece: