I have a search box web part. In that web part I have created an instance of SearchBoxEx like
SearchBoxEx par=new SearchBoxEx
par.goImageUrl=""
par.DropDownMode= DropDownModes.DisplayScopeDD;
Button sear= new Button();
sear.Click += new EventHnadler(sear_Click);
I have added a button to that search Box web part.Now I have to read the scope selected in the SearchBoxEx in the sear_Click event.Can anyone please guide me in the right direction
Any help would be really appreciated.
You could read the Request.QueryString["s"] parameter, even when it is a post, the SearchBoxEx adds it.
Edit
Based on the comments and new info, are you using 'pure' javascript? This would be a jquery example:Search
WARNING: You should change the site masterpage INSIDE your site with SharePoint designer, not the one in the C:\Program Files\etc... folder. You could also navigate to the http://yourportal/_catalogs/masterpage library and download a copy of the default.master to change it then upload it back to the library, do all this carefully, you can break your sharepoint very easily.
Insert above the </HEAD> tag in your masterpage:
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function newSearchResultsPageWithScope()
{
var scope = $(".ms-sbscopes select").val();
location.href = "/CustomResultsPage.aspx?s=" + scope;
}
</script>
The jquery portion is pretty straightforward, it gets the <td> with the class="ms-sbscopes", and the <select> element under it, then it sets the 'scope' variable to the selected value of the scopes dropdown.
Also, customizing the masterpage in a sharepoint site is fine, do not worry with that.
Related
We are replacing the forms for our lists with forms built with SPFx. Building and deploying the form is no issue. The problem is redirecting the form controls to this form (when a user opens an item or clicks new, etc...). Is there a recommended method of accomplishing this? I have been successful using two methods but they both seem volatile and hacky.
The first being replacing the entire form code using SharePoint designer. For instance, the new form code would be
<%# Page language="C#" %>
<html lang="en">
<head>
<script type="text/javascript">
const list = window.location.href;
const site = list.substring(0,list.toLowerCase().indexOf('/lists/'));
window.location.replace(site + "/SitePages/MyListForm.aspx");
</script>
</head>
<body>
</body>
</html>
This works sometimes... Upon saving, the form code seems to regenerate the form code but the redirect still works. However, if I open and save the code again, everything breaks and the list action goes back to default (clicking new would now show the 'New Item' call out instead of directing to the form).
The other method is opening the new/edit/display form in the browser, with ?toolpaneview=2 which allows me to add a script web part to the page (although it doesnt like to save) and add the script redirect in.
<script type="text/javascript">
const list = window.location.href;
const site = list.substring(0,list.toLowerCase().indexOf('/lists/'));
window.location.replace(site + "/SitePages/MyListForm.aspx");
</script>
this seems to be less volatile than the first method, but it still seems hacky. If I delete the original form web part, the form breaks and the list actions again revert to default. Editing the script requires visiting the form with ?contents=1 to delete the script web part and then I have to re-add it again using the toolpaneview method. In order to even save the web part change I have to click "Edit Web Part", which in turn saves it. There is no simple "Save" action which again makes me feel like this method is not intended to be done.
Is there any recommended way to accomplish these redirects? I've found plenty or tutorials online about setting up the list form, but nothing about this essential step.
SharePoint 2010 Custom List Form Tool Tip Field Help
I have a custom form in SharePoint and I need to add to formatted field help on mouseover, what is a good way to accomplish this?
STandard tooltips go away to fast.
Oh, by the way, we are NOT using InfoPath we are using SharePoint designer. We use to use Overlib but can't get it to work with SharePoint code.
Thanks for suggestions
We can use jQuery Tooltip from jQuery UI to achieve it. The code below for your reference:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function(){
$("input[title='Title']").tooltip();
})
</script>
Add the code to a content editor web part in the custom form page. This code works for the Title field, you can add similar code to make it works for other fields.
I have a document library in SP2013 that is full of forms. My users get confused by the "Check Out Required" box that pops up when they open the file. I keep telling them they need to download a copy, but this seems to be an issue. So, I looked into adding a "Download a Copy" button or link to the library, and came up with this solution, which is put in a snippet on a Web Part Page (source: https://amalhashim.wordpress.com/2013/11/29/sharepoint-2013-document-library-download-a-copy-button/):
<script type="text/javascript">
function runAfterEverythingElse(){
var elementArray = document.getElementsByClassName("ms-vb-lastCell");
var idArray = document.getElementsByClassName("ms-listlink");
for(var i = 0; i < elementArray.length; i++)
{
elementArray[i].innerHTML = '<a unselectable="on" href="javascript:;" onclick="window.open(\''+ idArray[i]['href'] + '\')" class="ms-cui-ctl-large " aria-describedby="Ribbon.Documents.Copies.Download_ToolTip" mscui:controltype="Button" role="button" id="Ribbon.Documents.Copies.Download-Large"><span unselectable="on" class="ms-cui-ctl-largeIconContainer"><span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float"><img unselectable="on" alt="" src="/_layouts/15/1033/images/formatmap32x32.png?rev=31" style="top: -409px; left: -35px;"></span></span><span unselectable="on" class="ms-cui-ctl-largelabel">Download a<br>Copy</span></a>';
}
}
_spBodyOnLoadFunctionNames.push("runAfterEverythingElse");
This partially works, in that it puts a button next to each document that says "Download a copy," but the action is actually just open the file in Word (instead of in the browser). The check-out prompt is still there, so I know it's opening the file and not downloading a copy. So while I like the way it looks, but the functionality isn't right.
In the answers to another question here (How to trigger a file download when clicking an html button or javascript), I found some instructions, but I can't figure out how to use them. I tried creating a workflow that created a download link and put it in an html-formatted field, but can't get the formatting right.
I don't really care if the solution is library-based (a field on each document probably created through Nintex Workflow) or Web Part Page based (script/snippet). I'm not fluent with jquery, javascript, or other programming languages. I know HTML, and can fumble my way through with CSS, but I'm pretty much a straight copy-paste from the internet solution kind of girl. I am not a programmer, just the person who manages our SharePoint site alongside may other job functions. :)
Any advice on how to tweak the original code or how to do this better is greatly appreciated. We're using SP2013.
#Kelly I implemented this solution in sharepoint 2010 using Dataview webpart.
Dataview webparts loops through all the documents in doc library and below code allow user to download the file.
Test.docx - Download a copy
I hope it helps. :)
Brief description of the default behavior i want to override:
Creating a SharePoint list and using the "Title (linked to Item)" in a view provides a link to the DispForm for that list. By default, this link appends a Source parameter to the URL query string.
I would like to disable this behavior in some way while still retaining the default list view web part that is created by SharePoint when the view is defined.
To be clear, I know how to convert the list-view webpart to XSLT and then control this behavior. If at all possible, I'd like to keep from doing that so that the list view can still be easily supported by Help Desk and also keep the benefits of the standard list view (such as exporting to excel and so forth).
Any ideas?
Thanks in advance for your help.
Troy
SharePoint (2007) dynamically appends the source parameter in a javascript method named GoToLink. That method is defined in SharePoint's core.js file, and it can be easily customized without editing the original file. In fact, you never want to edit that file directly; it will put SharePoint into an "unsupported" state.
We'll create a solution for our customization, so it can easily be deployed or retracted in a consistent manner. Create a new Empty SharePoint solution in Visual Studio, targeted for GAC deployment. Within your project, create the following folder structure:
Templates
Layouts
1033
("1033" is for the English localization; if you're using a different language, your id will be different).
Within "1033", create a new Javascript file (we call our ours "CustomCore.js"). This will contain JUST the code we want to override from Core.js. Since GoToLink is the only thing we're interested in, let's focus on that. Here's the original from Core.js:
function GoToLink(elm) {
if (elm.href==null)
return;
var ch=elm.href.indexOf("?") >=0 ? "&" : "?";
var srcUrl=GetSource();
if (srcUrl !=null && srcUrl !="")
srcUrl=ch+"Source="+srcUrl;
var targetUrl=elm.href+srcUrl;
if (isPortalTemplatePage(targetUrl))
window.top.location=STSPageUrlValidation(targetUrl);
else
window.location=STSPageUrlValidation(targetUrl);
}
Not much to it. For our override, we just need to omit the bits that add the source parameter. From my reckoning, the modified method looks like this:
function GoToLink(elm) {
if (elm.href==null)
return;
if (isPortalTemplatePage(elm.href))
window.top.location=STSPageUrlValidation(elm.href);
else
window.location=STSPageUrlValidation(elm.href);
}
That should be it. Package up the solution and Visual Studio should interpret the "Templates" folder structure correctly when it builds the WSP (look in the generated manifest file for the TemplateFile element and that it's deploying to "Layouts\1033\CustomCore.js").
Once your WSP solution is deployed to SharePoint, we have the final step of referencing it in your Master page. In the HEAD section of your master page, you should see Core.js being referenced like this:
<SharePoint:ScriptLink Language="javascript" runat="server" Defer="True" Name="core.js"/>
We simply add a reference to the new JS file directly beneath this line:
<SharePoint:ScriptLink Language="javascript" runat="server" Defer="True" Name="core.js"/>
<SharePoint:ScriptLink Language="javascript" runat="server" Defer="True" Name="customcore.js"/>
Test it out and make sure it works. Note that this will affect ALL lists on the server to which you've deployed "CustomCore.js" and which use the master page.
I have a sharepoint list and the phone number field is in the format ###-###-#### and it ends up going to 2 lines. How can I set a width on that particular column? Do I need to do it from sharepoint designer?
there is no way to do this out of the box. Have to use sharepoint designer or jquery. Check out this msdn post
http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/f99303bb-6a95-4c05-951c-ff0185c4e864
This can be done via the xsltlistform webpart. drop it into the page in sharepoint and connect it to your list and move the columns around as needed.
Note: this is not the same as modifying the view, which as titan said is not available out of the box without opening the view page in sharepoint designer and modifying the xslt directly.
Best way is to use Alt+0160 Hard Space. Just type it once and copy this "Space" and paste as many you want!! Bingo!!
In SharePoint Designer 2010 I was able to modify column widths by opening the view I wanted to adjust, then lengthening the with of the column Title Field simply by dragging the field's box bigger.
This worked for what I was doing, but I noticed with some columns it affected others, I guess because they shared the same styling? I don't know enough to be certain.
<style>
/* new class created */
.ms-longg
{
width:500px
}
</style>
<script type="text/javascript">
$(document).ready(function(){
//removed existing class
$('input[title^="State"]').removeClass('ms-long');
//add New class for that textbox
$('input[title^="State"]').addClass('ms-longg');
});
</script>
Click here see more details
you can also use the below script to expand the width of specific column. Just edit the page then add script editor web part and add below code.
note: the column name is the internal name.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js">/script>
<script language="javascript" type="text/javascript">
jQuery(document).ready(function() {
var el = document.getElementsByName("<internal column name>");
el[0].style.width ="<size>";
});
</script>