Tuesday, February 26, 2013

Fetch document and list url dynamically and open in pop-up

 Below is the script to fetch the document or list and its root folder dynamically:

<script src="/SiteAssets/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script><script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script><script src="/_layouts/SP.UI.Dialog.debug.js" type="text/javascript"></script><script type="text/javascript">

        $(document).ready(function () {
            SP.SOD.executeOrDelayUntilScriptLoaded(initialize, 'SP.js');
            SP.SOD.executeOrDelayUntilScriptLoaded(test, 'SP.js');
        });
        function getUrlVars() {
            var vars = {};
            var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
                vars[key] = value;
            });
            return vars;
        }

        var listID = getUrlVars()["List"]
        var rootFolder = getUrlVars()["RootFolder"];
               
               
        function openDiaForm() {
                       var diaOptions = SP.UI.$create_DialogOptions();
            diaOptions.url = '/_layouts/Upload.aspx?List='+listID+'&RootFolder='+rootFolder+'&IsDlg=1';
            diaOptions.width = 800;
            diaOptions.height = 600;
            diaOptions.title = "Upload Document Form";
            diaOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
            SP.UI.ModalDialog.showModalDialog(diaOptions);
        }
        //The function refreshes the content of the Document Set Welcome Page after the Upload Document modal dialog box has been closed 
        function CloseCallback(result, target) {
            location.reload(true);
        }
        function runCode() {
            var x = ExecuteOrDelayUntilScriptLoaded(openDiaForm, "sp.js");
        } 
    </script><a onclick="runCode();" href="#">Upload Proposal</a>

Friday, February 15, 2013

Asp.net Calender control on Textbox Click

Below is the sample to display a calender control on asp.net click event of Textbox..

On .aspx page write  the below code: then
<asp:TextBox ID="txtDate" runat="server" onclick="popupCalendar()"/>
   <div id="dateField" style="displaynone;">
  <asp:Calendar ID="calDate" OnSelectionChanged="calDate_SelectionChanged" 
runat="server" OnVisibleMonthChanged="calDate_OnVisibleMonthChanged" />
    </div>

Then write the below javascript: 

<script type="text/javascript">
        function popupCalendar() {
            var dateField = document.getElementById('dateField');
 
            // toggle the div
            if (dateField.style.display == 'none')
                dateField.style.display = 'block';
            else
                dateField.style.display = 'none';
        }
</script>
Then on the code behind file write the below code:

protected void calDate_SelectionChanged(object sender, EventArgs e)
        {
            txtDate.Text = calDate.SelectedDate.ToString("d");
        }
 
 protected void calDate_OnVisibleMonthChanged(object sender, MonthChangedEventArgs 
                                                                       e)
    {
        ClientScript.RegisterStartupScript(calDate.GetType(), 
                       "myScript", "popupCalendar()", true);
    } 

Its done, Below is the calender view: