There is requirement to access the control placed inside the PlaceHolderMain in the master page.
Enjoy!!!
There is requirement to access the control placed inside the PlaceHolderMain in the master page.
Enjoy!!!
location.href = "http spvm:1234.com/"
The following code will display the URL of the current page:
document.write(location.href)
protocol - The URL protocol section including the colon after the protocol name. The values are normally http: or file
This is the first article in exploring the power of javascript when called from XSLT.
XSLT is basically used to render the xml in specified format.Here the requirement is to call some javascript function when xslt is rendering the xml.
In this article we are calling javascript on page load .
Scenario : On page load we want to fill some value in text box coming coming from the property defined in the xml .So first we need to access the property value inside javascript and then on page load need to fill the value inside the textbox.
Here is the sample javascript to be used inside the sample.xsl file
<xsl:template name="picture">
<script type="text/javascript">
function myFunction()
{
var url = ']]><xsl:value-of select="substring-before(@PictureUrl, ',')" />';
var txtBox = document.getElementById('textBox');
txtBox.value = url;
}
_spBodyOnLoadFunctionNames.push("myFunction");
]]>
script>
xsl:template>
Keep watching this space for more in javascript and XSLT.If you have done something then please share.
This is bit tricky one as often we have some feature receiver class with the feature and we want to debug it .
When we activate the feature through UI (ie from the site features) we attach the w3p process and debug the feature receiver code but this does not happen while doing the same from command prompt
So for this follow these steps :
1) Type the command to activate the feature in command prompt :
Stsadm –o activatefeature –name “feature name” –url
2) As soon u press enter , press Pause button from the keyboard.
There should not be any delay in these two actions as this is very fast process .
3) Now go to the solution in visual studio and attach the “stsadm” process from attach process tab
4) Now come to command prompt and press any key to resume the process.
Now you can debug the feature receiver code
So your job is done.
Enjoy!!!
To get the Date Time related information from the site’s Regional settings ,here is the sample code snippet.
SPSite site = new SPSite("http://spvm:1234/");
SPWeb web = site.OpenWeb();
DateTime dt = web.RegionalSettings.TimeZone.LocalTimeToUTC((DateTime.Now));
This way we can get the current time zone settings like which time zone we are using and date and time
So your job is done
Enjoy !!!
Requirement is to get the querystring value through javascript.
Here Querystring variable name is “Tag”
Add this function in the javascript block of the page and call according to the requirement.I am calling this function on page load.
Here is code:
-----------------------------
Recently i faced a problem in event handler to do some operation for the current logged in user,but inside event handler SPContext object is null. So after some probe we found a way to get the current user object .
For this we need to get the HttpContext object inside the constructor of the event handler
Here is the sample code :
———————————————–
HttpContext current;
///
/// Constructor to get the current logged in user details
///
public ListEventHandler()
{
current = HttpContext.Current;
}
Now to get the login name of the current user use this code:
string currentUserLoginName = current.User.Identity.Name;
————————————–
So your job is done
Enjoy!!!
Enjoy!!!
Objective is to add the listviewer web part on the page programmatically. I have a document library for which i want to add the list viewer web part on any page.
Create a console application and paste the code
Code snippet
class Program
{
static void Main(string[] args)
{
SPSite site = new SPSite(”Site Url”);
SPWeb oSubWeb = site.OpenWeb();
oSubWeb.AllowUnsafeUpdates = true;
//Get the object of the page as SPFile on which we need to add the listviewer webpart
SPFile oFile = oSubWeb.GetFile(”default.aspx”);
//Create the object SPLimitedWebPart Manager
SPLimitedWebPartManager oWebPM = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
//Get the object of the list of which we are creatin the list viewer webpart
SPList oSubSiteList = oSubWeb.Lists["Shared Documents"];
//Create the object of ListViewer webpart
ListViewWebPart oListViewWP = new ListViewWebPart();
//Set the properties of the webpart
oListViewWP.ChromeType = PartChromeType.TitleOnly;
oListViewWP.Title = “Shared Documents”;
oListViewWP.ListName = oSubSiteList.ID.ToString(”B”).ToUpper();
//Define the zone in which webparts need to be added
oWebPM.AddWebPart(oListViewWP, “Zone 1″, 1);
}
}
Your job is done….
Enjoy!!!
If you find this post useful then please post your comments
In this post I am using SPGrid view inside a webpart.
First we need to initialize the SPGrid view control in the Create Child control mehod and specify its properties
Use this code inside CreateChildControl method
—————————————————————
//Initialize the control
SPGrid CustomGrid;
CustomGrid = new SPGridView();
CustomGrid.Width = Unit.Pixel(700);
this.CustomGrid.ID = “Customgrid”;
//Specifying the Eventhandler for Paging
this.CustomGrid.PageIndexChanging += new GridViewPageEventHandler(CustomGrid_PageIndexChanging);
this.CustomGrid.AutoGenerateColumns = false;
//Specifying the grid properties
this.CustomGrid.PageSize = 10;
this.CustomGrid.BackColor = System.Drawing.Color.White;
this.CustomGrid.GridLines = GridLines.Horizontal;
//Allowing Paging on the Grid
this.CustomGrid.AllowPaging = true;
this.CustomGrid.EnableViewState = true;
this.CustomGrid.TemplateControl = null;
//Creating Boundfields in the Grid view
BoundField DealName = new BoundField();
DealName.DataField = “Name”;
DealName.ItemStyle.Width = Unit.Percentage(30);
DealName.ItemStyle.Wrap = true;
this.Controls.Add(CustomGrid);
CustomGrid.PagerTemplate = null;
—————————————————————–
Once the declaration and initialization of control is done we need to define the pagination of the SPGrid
This is the method for the pagination event
—————————————————–
// Method for Page indexing
void CustomGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
CustomGrid.PageIndex = e.NewPageIndex;
CustomGrid.DataBind();
}
catch (Exception ex)
{
}
}
Your job is done ..
Enjoy!!!