Nov 14, 2011

Call a client side javascript method after a specific update panel has been loaded

<script type="text/javascript"> 
    $(document).ready(function() { 
    panelsLoaded = 1;
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded) }); 

    function PageLoaded(sender, args) { 
        console.log("I have occured " + panelsLoaded++ + " times!"); 
        var panelsCreated = args.get_panelsCreated(); 
        for (var i = 0; i < panelsCreated.length; i++) 
        { 
            console.log("Panels Updating: " + panelsCreated[i].id); 
        } 
        var panelsUpdated = args.get_panelsUpdated(); 
        for (var i = 0; i < panelsUpdated.length; i++) 
        { 
            console.log("Panels Updating: " + panelsUpdated[i].id);
        }
    } 
</script>

Just add all the scripts in the PageLoaded() function.



Nov 2, 2011

Watch hulu outside US

http://lifehacker.com/5583515/access-hulu-from-outside-the-us-without-a-proxy-server



Jun 16, 2011

Insert multiple rows of Data in SQL server using XML

The XML must be like:


<surveys>
    <survey SurveyId="#SurveyId#"
            QuestionId="#QuestionId#"
            Answer="#Answer#"
            UserId="#UserId#"
            UserName="#UserName#"/>
    <survey SurveyId="#SurveyId#"
            QuestionId="#QuestionId#"
            Answer="#Answer#"
            UserId="#UserId#"
            UserName="#UserName#"/>
    <survey SurveyId="#SurveyId#"
            QuestionId="#QuestionId#"
            Answer="#Answer#"
            UserId="#UserId#"
            UserName="#UserName#"/>
</surveys>

This XML must be passed as argument to stored procedure. Create a stored procedure and pass the XML document as a parameter. In the example below @XMLDOC is a string variable with the actual XML passed to it.


DECLARE @xml_hndl INT

--prepare the XML Document by executing a system stored procedure
EXEC SP_XML_PREPAREDOCUMENT @xml_hndl OUTPUT, @XMLDOC

BEGIN TRY
    BEGIN TRANSACTION
        INSERT INTO SurveyResponse

        SELECT SurveyId, 
               QuestionId, 
               Answer, 
               UserId, 
               UserName, 
               GETDATE(), 
               GETDATE()
        FROM
        OPENXML(@xml_hndl, '/surveys/survey', 1)
        WITH
         (
             SurveyId BIGINT '@SurveyId',
             QuestionId BIGINT '@QuestionId',
             Answer INT '@Answer',
             UserId VARCHAR(100) '@UserId',
             UserName VARCHAR(200) '@UserName'
         )

        SET @return = 1
    COMMIT
END TRY
BEGIN CATCH
    ROLLBACK
    SET @return = 0
END CATCH


Mar 25, 2011

Attach excel to SQL Server DB as linked server

Query to attach excel to DB as linked server.

EXEC sp_addlinkedserver 'ImportData',
                        'Jet 4.0', 'Microsoft.Jet.OLEDB.4.0',
                        'D:\Working\Web_Analytics_Requirements.xls',
                        NULL,
                        'Excel 8.0'
GO
--ImportData is the name of new linked server
--D:\Working\Web_Analytics_Requirements.xls is the path to excel
--Excel 8.0 is for MS office 2003

To insert the spreadsheet as a table in database

INSERT INTO dbo.ImportTest
SELECT *
FROM OPENQUERY(ImportData, 'SELECT * FROM [Summary$]')
--ImportData is the name of linked server
--Summary is the name the spreadsheet

To directly fetch values from linked server (excel file)

SELECT * FROM ImportData...Summary$

Feb 24, 2011

Header& Footer in a web page

The body tag should be like:



<body>
    <form id="master" runat="server">
        <div id="pageheader"></div>
        <div id="pagebody">
            <div>CONTENT</div>
        </div>
        <div id="pagefooter"></div>
    </form>
</body>
CSS for this tag should be:
body
{
    margin:0px;
    font-family:Calibri;
    font-size:15px;
    padding: 40px 0 25px 0;
    _padding-top:0px; /*for ie 6*/
    overflow:auto;
}
#pagebody
{
    overflow:auto;
    min-width:100%;
    vertical-align:middle;
    text-align:center;
}
#pageheader
{
    position:fixed;
    top:0px;
    left:0px;
    width:100%;
    height:40px;
    border-bottom:1px solid #FF6633;
    background-color:#FFFFFF;
    vertical-align:bottom;
}
#pagefooter
{
    position:fixed;
    _position:absolute;/*for ie 6*/
    bottom:0px;
    left:0px;
    width:100%;
    height:25px;
    border-top:1px solid #FF6633;
    text-align:left;
    vertical-align:bottom;
    background-color:#FFFFFF;
}
Add this section to head:
<!--[if !IE 7]>
    <style type="text/css">
        #pagebody {display:table;height:100%}
    </style>
<![endif]-->