I am newbie with sharepoint, struggling but finding my way.

I have created a list and created a new form called NewFormRequest.aspx in SharePoint designer.

I am calling this form in the browser:


Which is ok.

  1. I have a column there named Requested user: This should be a label, which I did and the question is when this forms opens I should be able to set the user who opens the forms. Where and how can I do that?

  2. I googled and find some code on web like:

    SPSite oSiteCollection = new SPSite("Absolute_URL");

But I don't know where the code-behind file (*.aspx.cs) is so where to put this C# and more code?

  1. I like to add javascript code for styling the form (hide/show) etc. So, I opened the "NewFormRequest.aspx" in SPD but where do I put javascript code?

I mean I just pressed Space bar key and it added a tag < WebPartPages:WikiContentWebpart in the "NewFormRequest.aspx" and I put the javascript code between this tag, it worked. But is this the place where I put my javascript xxxx code?

so several questions.

1 Answer 1

  1. I'm not too sure about the question. If you mean something like auto-filling the label with the current user, you can request the current user object which has information like email, display name, log in name, etc. Check out SP.ClientContext to do this using client-side scripting.

  2. Check out http://www.wictorwilen.se/Post/The-simplest-form-of-SharePoint-application-part-2.aspx for deploying C# code safely in SharePoint.

  3. To add javascript to SharePoint, after you have written the script:

a. upload the script to the Site Assets library in the site you are going to use the script. You can access the Site Assets easily in SharePoint Designer.

b. Right click on the .js you uploaded and get the full url of the this script file.

c. Insert a script editor web part in the .aspx page and add

<script src="url-of-the-.js-file-you-copied"></script>

Now your script will run in the relevant page. This method is better than directly writing your code to the script editor which would also work, btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.