Friday, 7 July 2017

Solution of Visual Web Parts Missing .ascx.g.cs In Visual Studio Issue

Issue: Sometimes it happens that designer (.ascx.g.cs) file is missing after saving the changes in Visual web part .ascx file and designer (.ascx.g.cs) file is not re-generating automatically.
Solution: Check and perform all the below steps:

1.      First check whether the project properties in which visual web part exists is having correct SharePoint Site URL and connected to server or not.
If it is connected, then it would look like below.
2.      Then check .ascx page properties, it should have SharePointWebPartCodeGenerator value for Custom Tool
3   If designer (.ascx.g.cs) file exists but if you made some changes in the HTML but its changes are not reflected in designer (.ascx.g.cs) file, then it might be the case of below.
To fix the problem you need to open up and edit the project .csproj file. Simply open the file and search for your web part, in my case I’m looking for the “SiteDescriptionWebPart” web part.

Once, you’ve identified the web part elements, you’ll need to check below code and do the changes as per required.
<Compile Include="SiteDescriptionWebPart\SiteDescriptionWebPart.ascx.cs">
      <DependentUpon>SiteDescriptionWebPart.ascx</DependentUpon>
    </Compile>
    <Compile Include="SiteDescriptionWebPart\SiteDescriptionWebPart.ascx.g.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>SiteDescriptionWebPart.ascx</DependentUpon>
    </Compile>

This all above steps will solve your designer (ascx.g.cs) file issues and it will re-generate the new designer file after saving any changes in the .ascx file.

Friday, 22 May 2015

Working with CSS with parent elements and iframe elements

Apply CSS to Parent elements within iframe


parent.$('#Wrapper').find('iframe').attr('style','height:800px !important')


where,
parent will be of the iframe contents i.e. parent page
#wrapper will be id of an element in parent page which contains iframe element.

Please note:- iframe element will be the parent page element.

Apply CSS to ifram elements within parent page


$('iframe').contents().find("body").html("Iframe content overwitten")

So, here we have to first get the iframe element so that we can get its contents and then any element can by find.

Similary you can easily work with CSS to and fro with them.

Friday, 24 April 2015

Client Side code for SharePoint using javascript

Hi friends,

Here I will write all basic client side code for SharePoint using JavaScript.


To add Item in SharePoint list

function AddItem(){
    var clientContext = new SP.ClientContext();   
    var entitylist = clientContext.get_web().get_lists().getByTitle("List1");
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var oListItem = entitylist.addItem(itemCreateInfo);  
   
    oListItem.set_item('Title', 'Test Title');
    oListItem.set_item('Body'', 'String field added.');
    oListItem.update();

    clientContext.load(oListItem);
    clientContext.executeQueryAsync(
        Function.createDelegate(this, function (sender, args) {
             alert("Item Added.");
        }),
        Function.createDelegate(this, function (sender, args) {
            console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }));
}

To update "DateTime" field in SharePoint list.

code within AddItem() function:

    var dt= new Date();   
    oListItem.set_item('LoginDateTime',dt.toGMTString());
    oListItem.update();


 To Update "User" field in SharePoint list.

   oListItem.set_item('User', clientContext.get_web().get_currentUser());
   oListItem.update();


I will update my this blog post from time to time. So keep in touch...

Thursday, 23 April 2015

To get querystring variable of Parent Page URL from iframe


To get Parent page url from iframe:

string url = HttpContext.Current.Request.UrlReferrer.OriginalString.ToString();

To get QueryString from url of parent page, use:

string query = HttpContext.Current.Request.UrlReferrer.Query;

To get values of parameters from url use:

string[] queryStringParaArray = HttpContext.Current.Request.UrlReferrer.Query.Substring(1).Split('=');

     if (queryStringParaArray.Length > 0)
     {
        foreach (var para in queryStringParaArray)
             if (para == "EventId")
                 int eventId = Convert.ToInt32(queryStringParaArray[1]);
     }