Advertisements
RSS

Tag Archives: ASP.NET

JavaScript: Cookies


A cookie is a variable that is stored on the user’s computer. You can use Javascript to create and retrieve cookie values.

To create a cookie:


function setCookie(sCookieName, sCookieValue)
{
var oCookieExpiryDate = null;
try
{
oCookieExpiryDate = new Date();
if (oCookieExpiryDate == null)
{
return -1;
}
oExpiryDate.setTime(oCookieExpiryDate.getTime() + (1000 * 60 * 60 * 24 * 30)); //30 days
document.cookie = sCookieName + "=" + sCookieValue + "; path=/" + ((oCookieExpiryDate == null) ? "" : "; expires=" + oCookieExpiryDate.toGMTString());
}
catch(e)
{
}
finally
{
}
}

To get the value of a cookie:


function getCookie (sCookieName)
{
try
{
var sCookieNameEQ = sCookieName + "=";
var oCookiesArray = document.cookie.split(';');
for(var i=0;i < oCookiesArray.length;i++)
{
var oCookieItem = oCookiesArray[i];
while (oCookiesArray.charAt(0)==' ')
{
oCookieItem = oCookieItem.substring(1,oCookieItem.length);
}
if (oCookieItem.indexOf(sCookieNameEQ) == 0)
{
return oCookieItem.substring(sCookieNameEQ.length,oCookieItem.length);
}
}
return null;
}
catch(e)
{
}
finally
{
}
}

 

Advertisements
 
Leave a comment

Posted by on October 10, 2012 in Programming

 

Tags: , , , , , , , , , , , ,

ReportViewer Error : Operation is not valid due to the current state of the object


I was getting this error in my ASP.NET application when I try to load a report into the report viewer control. To solve this I used the Reset() method of the report viewer control.



oReportViewer.Reset()
oReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
oReportViewer.Visible = True
oReportViewer.ServerReport.ReportServerUrl = New System.Uri(sReportServiceURL)
oReportViewer.ServerReport.ReportPath = sReportName
oReportViewer.ShowParameterPrompts = False
oReportViewer.ShowDocumentMapButton = False
oReportViewer.DocumentMapWidth = 0
oReportViewer.ShowDocumentMapButton = False
oReportViewer.ShowFindControls = False
oReportViewer.ServerReport.Refresh()

 
Leave a comment

Posted by on September 27, 2012 in Programming

 

Tags: , , , , , , , , , ,

Using ASP.NET Mobile Forms

I wanted to use the normal ASP.NET Forms stuff in a mobile form.

  • Right click on the web site project and select Add new Item

1

  • Select Mobile Web Form. enter a name for the form and click on Add button

2

  • To use a style sheet & a JavaScript file, I added a DeviceSpecific with SupportJavaScript Filter. this is how the HTML code looks like

3 

  • Now I wanted to created some ASP controls. so I added another DeviceSpecific with isHTML32 Filter. this is how the HTML code looks like

4

 

  • One last thing, in order to make those DeviceSpecific Filters to work you need to add the required keys in the web.config file. this is how this would look like

untitled

 
2 Comments

Posted by on February 5, 2010 in Programming

 

Tags: , , , , , , , , , , , , , , ,

GridView: Wrong Fields Order

 

I was working on a GridView that is binding to a custom class collection to display its properties. the fields in the GridView were ordered depending on the order of the properties in the Class. everything was working fine. until I moved the code to a different development environment.

In the new development environment the order of the GridView fields was not as expected. after spending a lot of time trying to fix that. I installed the .NET 2.0 service pack 2 and that solved the problem!!!!

You can download the .NET 2.0 SP2 from here

http://www.microsoft.com/downloads/details.aspx?familyid=5B2C0358-915B-4EB5-9B1D-10E506DA9D0F&displaylang=en

 
Leave a comment

Posted by on January 27, 2010 in Programming

 

Tags: , , , , , , ,

C#: Bind a DropDownList to IDictionary using AjaxPro

Implement an AjaxMethod to return IDictionary object

 

[AjaxPro.AjaxMethod]

public IDictionary AjaxGetIDictionary()

{

//Prepare the IDictionary object

}

– Use JavaScript to request the AjaxMethod AjaxGetIDictionary

MyAjaxClass. AjaxGetIDictionary (jsAjaxGetIDictionary_Callback);

– In the JavaScript function jsAjaxGetIDictionary_Callback add the IDictionary items to the DopDownList

function jsAjaxGetIDictionary (response)

{

     try

    {

         var DictionaryItems= response.value;

         if (DictionaryItems == null || typeof(DictionaryItems) != “object”)

        {

               return;

         }

         var myDropDownList = document.getElementById(“myDropDownList”);

         myDropDownList.options.length = 0;

         for (var i = 0; i < response.value.length; ++i)

         {

             myDropDownList.options[myDropDownList.options.length] = new Option(response.value[i].Value,response.value[i].Key);

           }

    }

    catch(e)

   {

   }

}

 
Leave a comment

Posted by on May 1, 2009 in Programming

 

Tags: , , , , , , , , ,

Using AJAX Pro (step by step):

This is a simple guide for using the AJAX Pro in VS2003

 

1-     Add the AJAXPro.dll to your bin folder

 

         Right click on the bin folder and select “Add Reference… ”

 

 

 

         Select the browse tab and browse for the AjaxPro.dll folder to select it and click ok

 

 

2-     Add the following to your web.config file

 

<httpHandlers>

          <add verb=POST,GET path=ajaxpro/*.ashx type=AjaxPro.AjaxHandlerFactory, AjaxPro.2/>

</httpHandlers>

 

3-     Create a Class to write your Ajax functions

         Right Click on the App_Code folder and select “Add New Item…”

 

 

         Select “Class” from the templates; enter a name for your class and click Add

 

 

4-     In your class imports the AjaxPro Library and create your function as the following:

 

       <AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)> _

Public Function AjaxFunction(ByVal strVariable As String) As String

 

5-     In the ASP Page that need to use the Ajax Function:

 

         Import your Ajax Class library

         Add a function to the body onload event

<body   onload=”BodyOnLoad()”

         In the BodyOnLoad assign a variable to your class

 

function BodyOnLoad()

                    {

                       LPMyAjax = IMGSLB.MyAjax;

     }

 

 

6-     Now you can call the ajax function from JavaScript

 

    function jsCallAjax(strValue)

    {

        try

        {

           

            LPMyAjax.AjaxFunction(strValue,jsCallAjaxCallback);

        }

        catch(err)

              {

            alert(err.message)

              }

              finally

              {

                    

              }

    }

 
1 Comment

Posted by on July 16, 2008 in General, Photography

 

Tags: , , , , , , , , ,

AjaxControlToolkit’s TabContainer: Navigation Buttons With Scroll Header

I used the code from Matt Berseth to create navigation buttons to change the selected tabs, but as I was using the tabs in a Left frame in the Web application; I did not have enough space to display all the tabs headers, the navigation buttons was working fine but the headers was invisible, so I changed the code to add a horizontal scrolling for the Header. I am creating dynamic tabs so I do not know the required value of the scroll as I do not know the width of the headers, and so I am using (_header.offsetWidth) for the active tab as a scroll value

 

HTML code:

 

 

<cc2:TabContainer  AutoPostBack=”false” style=”Z-INDEX: 102; LEFT: 0px; POSITION: absolute; TOP: 18px”  ID=”TabContainer1″ runat=”server” Width=”100%”>

</cc2:TabContainer>

          

<asp:ImageButton  ImageUrl=”images/scrollnext.gif”  id=”tabNext” ToolTip=”Next tab”   OnClientClick=”onNavigate(true); return false;”  style=”Z-INDEX: 102;  POSITION: absolute; TOP: 0px;  left:20px      runat=”server” />

<asp:ImageButton ImageUrl=”images/scrollpre.gif” id=”tabPrev” ToolTip=”Previous tab” OnClientClick=”onNavigate(false); return false;”  style=”Z-INDEX: 102;  POSITION: absolute; TOP: 0px; “  runat=”server” />

 

JavaScript functions:

 

    function onNavigate(isMoveNext)

    {

        //  find the behavior for the tab control

        var tabs = $find(‘TabContainer1’);

        //  figure out what the total number of tabs are

        var totalNumOfTabs = tabs.get_tabs().length;

        //  if we don’t have any tabs, just return

        if(totalNumOfTabs > 0)

        {

            var newTabIndex;

            var currentTabIndex = tabs.get_activeTabIndex();

            if(isMoveNext)

            {

                //  wrap around to the begining

                if(currentTabIndex + 1 == totalNumOfTabs)

                {

                    newTabIndex = 0;

                }

                else

                {

                    newTabIndex = currentTabIndex + 1;

                }

            }

            else

            {

                //  wrap around to the end

                if(currentTabIndex – 1 < 0)

                {

                    newTabIndex = totalNumOfTabs – 1;

                }

                else

                {

                    newTabIndex = currentTabIndex – 1

                }

            }

            tabs.set_activeTabIndex(newTabIndex);

            var aTab  = tabs.get_activeTab()

            if(isMoveNext)

            {

                if (newTabIndex == 0)

                {

                    document.getElementById(“TabContainer1_header”).scrollLeft=0;}

                else

                {

                    scrollDivLeft(“TabContainer1_header”,aTab._header.offsetWidth);}

                }

            else

            {

                if (newTabIndex == totalNumOfTabs – 1)

                {

                    document.getElementById(“TabContainer1_header”).scrollLeft=totalNumOfTabs*aTab._header.offsetWidth;

                }

                else

                {

                    scrollDivRight(“TabContainer1_header”,aTab._header.offsetWidth);

                }

            }

        }

    }                                                             

                            

          function scrollDivLeft(id,scrollStep)

          {

        document.getElementById(id).scrollLeft+=scrollStep

    }

 

    function scrollDivRight(id,scrollStep)

    {

        document.getElementById(id).scrollLeft-=scrollStep

    }

 

 

And this how the header looks like

 

 

 
5 Comments

Posted by on June 26, 2008 in General, Photography

 

Tags: , , , , , , , , ,

 
%d bloggers like this: