This project is read-only.

Referencing controls from a usercontrol

Apr 11, 2009 at 12:34 PM

Hello guys

First of all I would like to thank you for this project.

However I do have two questions

1.

I want to use the peoplepicker in my usercontrol.

But how do I reference the peoplepicker from the script part in my usercontrol to save the data that is filled in ?

2.

In my usercontrol I want to show the document (is always pdf) that is related to the task.

To do this I want to use the Iframe control.To do this I think I have to do the following from codebehind:

Init control

protected System.Web.UI.HtmlControls.HtmlGenericControl frame1

Find control

HtmlControl frame1 = (HtmlControl)this.FindControl("frame1")

Change the source

frame1.Attributes["src"] = "http://www.live.com" ;

I think I have to do those things from the codebehind.

I have tried to make a codebehind for the usercontrol but the getdata and savedata  methods are not allowed in the codebehind

 

Properly I am missing something, is there somebody who can give me some direction

Many Thanks

Guillaume

Apr 11, 2009 at 5:23 PM
To the first part of the question:

If you want to use a people picker you'll need to place the control in your markup and access it from the codebehind.  There is probably a javascript interface but you'll really only need the codebehind part.  We used to have a demo with the PeoplePicker in it, unfortunately it doesn't work well in the designer.  If you have some code in place that is nearly working go ahead and post it and we can help.  I'll be back in my office in a week or so and I can modify it as needed to make it work.

To the second part:

I'm wondering if you're confusing the code in the c# script in the ascx as client side script.  The code in the script fragment in the ascx that has a runat property of server is actually codebehind that is compiled into the assembly.  You can move all of that code into a .cs file and reference it from the .ascx file directly if you want, although it does take some other work since you'll need to make sure the references line up correctly.  An easier solution is to put your code that finds the control and uses it right in the LoadData method in the .ASCX file.

For example:
<iframe id="documentFrame" runat="server" />

protected override void LoadData(...)
{
  if (isInitialLoad)
  {
    ...
    documentFrame.Attributes["src"] = documentUrl;
  }
}

Chris
Coordinator
Apr 12, 2009 at 8:33 AM
Chris is right here. Just to expand on it.

ASP.NET allows you to add code to a page or control using two methods, inline and code-behind.
Inline
Using the inline method you add your server side code in a <script runat="server"> block inside the markup of your page or control. Easy since there is only one file (the ASPX or ASCX) and no DLL to deploy. The ASP.NET parser / compiler will take the code you write in these script blocks and add it to the stuff it generates for you.
Our requirements for doing this is that you set the right base class in the < % @Page % > or < % @ Control % > directive using the Inherits attribute that you can use there. This is already done for you in our Visual Studio templates, so it is easy to use. Another thing making this approach easier is referencing controls that sit on your UserControl. If you have a control declared as <iframe id="myFrame" runat="server"> you can the easily type something like 'myFrame.Attributes["src"] = "my.pdf". E.g. you do not need to declare the 'myFrame' instance field in your code since ASP.NET adds it for you.


Code behind
Second option is code-behind. Using this approach you add your own class that derives from our base classes, like ConfigurationControl (the same as you will find in the < % @ Page %> or <% @ Control %> directives. Main benefit is that the code is now no longer in the declarative part (in the ASPX / ASCX). Which for some page types in SharePoint is not allowed (for site pages specifically, which are not used by the tools anyway).
If you take this approach you will need to declare any controls that sit on your page manually. So say that you have a <iframe id="myFrame" runat="server" /> on your page, you will need to declare this control in your code file as follows:
protected HtmlGenericControl myFrame.
The name of your variable matches the ID attribute. The variable is protected, and ASP.NET will automatically assign an instance to it, so you will *not* have to do a FindControl or something similar.

Hope it helps, and let us know if we can help out somewhere.


________________________________

Van: predeekc [mailto:notifications@codeplex.com]
Verzonden: za 11-4-2009 18:23
Aan: Wouter van Vugt
Onderwerp: Re: Referencing controls from a usercontrol [wss3workflow:52973]



From: predeekc

To the first part of the question:

If you want to use a people picker you'll need to place the control in your markup and access it from the codebehind. There is probably a javascript interface but you'll really only need the codebehind part. We used to have a demo with the PeoplePicker in it, unfortunately it doesn't work well in the designer. If you have some code in place that is nearly working go ahead and post it and we can help. I'll be back in my office in a week or so and I can modify it as needed to make it work.

To the second part:

I'm wondering if you're confusing the code in the c# script in the ascx as client side script. The code in the script fragment in the ascx that has a runat property of server is actually codebehind that is compiled into the assembly. You can move all of that code into a .cs file and reference it from the .ascx file directly if you want, although it does take some other work since you'll need to make sure the references line up correctly. An easier solution is to put your code that finds the control and uses it right in the LoadData method in the .ASCX file.

For example:
<iframe id="documentFrame" runat="server" />

protected override void LoadData(...)
{
if (isInitialLoad)
{
...
documentFrame.Attributes["src"] = documentUrl;
}
}

Chris

Read the full discussion online <http://wss3workflow.codeplex.com/Thread/View.aspx?ThreadId=52973&ANCHOR#Post178186> .

To add a post to this discussion, reply to this email ([email removed] <mailto:[email removed]?subject=[wss3workflow:52973]> )

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings <http://www.codeplex.com/site/discussions/project/unsubscribe/wss3workflow> on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com
Apr 14, 2009 at 10:13 AM
Edited Apr 14, 2009 at 10:19 AM

Thanks it is solved !

For the people picker:

I Added the following line to my ascx:

<%@ Register TagPrefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0,  Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Then I added the control itself:

<wssawc:PeopleEditor<o:p></o:p>

     AllowEmpty="false"

     ValidatorEnabled="true"

     id="userPicker"

     runat="server"

     ShowCreateButtonInActiveDirectoryAccountCreationMode="true"

     SelectionSet="User" />

 

In the inline script part I changed the following:

protected override ConfigurationData SaveData(object commandArgument)

    IncommingMailConfigurationData configData = new IncommingMailConfigurationData();        
    //gets first user in list
    PickerEntity
pe = (PickerEntity)userPicker.Entities[0]; 

    string username = pe.Description;

 

    configData.AssignedTo = username;

    return SaveDataAs<IncommingMailConfigurationData>(configData);

 }
  
2  IFrame

I  only used the name as a reference and not the id

Thanks

 Guillaume