Category Archives: Knockout

[RESOLVED] Declare a global instance of a list

Hi guys i want to declare a single instance of a list that can be used anywhere within the web app, how is that possible if it is ?? Please it is very urgent. Thanks

Is it a static list or loaded from a database?  Either way a class would be the way to go.

After you create your list you could save it to a session variable and then use it any where in your application.

Thanks.. I have a class that creates the list and handles adding data to the list.. I also have two form in my web app, on the home form that has a listbox control that goes through the list and display any data that is in the collection list to the listbox, and also a add form that adds data to the list. But the problem i am having is how to make sure that the home form uses the same instance of the list class as the add form... Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FitWeb4
{
    [Serializable]
    class FitnessClassList
    {
        private List<FitnessClassOpportunity> fitnessClassList;

        public FitnessClassList()
        {
            fitnessClassList = new List<FitnessClassOpportunity>();
        }

        public void addFitnessClass(FitnessClassOpportunity fitnessClassOpportunity)
        {
            //Make sure a class with this id does not already exist

            foreach (FitnessClassOpportunity f in fitnessClassList)
            {
                if (f.Id == fitnessClassOpportunity.Id)
                {
                    throw new DuplicateIdException();
                }
            }

            fitnessClassList.Add(fitnessClassOpportunity);
        }

        public void removeFitnessClass(int index)
        {
            fitnessClassList.RemoveAt(index);
        }

        public void removefitnessClass(FitnessClassOpportunity fitnessClassOpportunity)
        {
            fitnessClassList.Remove(fitnessClassOpportunity);
        }

        public FitnessClassOpportunity getFitnessClass(int index)
        {
            return fitnessClassList[index];
        }

        public int Count()
        {
            return fitnessClassList.Count;
        }

        public void Sort()
        {
            fitnessClassList.Sort();
        }
    }
}

This is the List Class.. that i want on instance of to be declared globally across my web app

create your DataSet by filling you list in DataSet and then put the DataSet object in Session like this :

Session["globallist"]=ds;

when you want to use

Dataset ds=(Dataset)Session["globallist"];

It will be global for your whole application

as same you can also use

Application["globallist"]=ds;

hope you know the difference, if dont ask again

I don't totally understand the dataset thing, if i declare a global instance of the class how do i access the individual method...

DataSet is used when you have to fill data from database

Session and Application variable can store any thing

put you List in Session/Application

Session["globallist"]=mylist;

Sorry but let me rephrase my question again. I have a class for example "class A". In this class I created a new list and I also have a method that holds the list and another method that adds to the list.

I have two web forms called "Home" and "Add". The home web form gets the data from the list in class A and the add submits the data to the list in "Class A" also. So I want an instance whereby a global instance of class A is created so that the Home and Add web form can use that same global instance of class A and access the methods in it, without having to create their own individual instance of class A.  Below is the sample of class A that i want a single global instance of..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FitWeb4
{
    [Serializable]
    class FitnessClassList
    {
        private List<FitnessClassOpportunity> fitnessClassList;

        public FitnessClassList()
        {
            fitnessClassList = new List<FitnessClassOpportunity>();
        }

        public void addFitnessClass(FitnessClassOpportunity fitnessClassOpportunity)
        {
            //Make sure a class with this id does not already exist

            foreach (FitnessClassOpportunity f in fitnessClassList)
            {
                if (f.Id == fitnessClassOpportunity.Id)
                {
                    throw new DuplicateIdException();
                }
            }

            fitnessClassList.Add(fitnessClassOpportunity);
        }

        public void removeFitnessClass(int index)
        {
            fitnessClassList.RemoveAt(index);
        }

        public void removefitnessClass(FitnessClassOpportunity fitnessClassOpportunity)
        {
            fitnessClassList.Remove(fitnessClassOpportunity);
        }

        public FitnessClassOpportunity getFitnessClass(int index)
        {
            return fitnessClassList[index];
        }

        public int Count()
        {
            return fitnessClassList.Count;
        }

        public void Sort()
        {
            fitnessClassList.Sort();
        }
    }
}


 Thanks...

Are these forms on the same page?  If one is adding data to the list don't you simply need to use an add function and then reload the list for the listbox?

The webform are not thesame pages they are on different webpages

As you have Serilaized your class you could always keep it in the ViewState:

ViewState["yourlist"] = yourloadedList;

And get access to it via:

List<FitnessClassOpportunity> yourloadedlist = List<FitnessClassOpportunity>ViewState["yourlist"];

This will only work if they are loaded on the same page.



If they are on different pages is there a reason why you cannot simply load the list from the database on page load?

Am i add this code to the Add form or the Home... Thanks I appreciate

Is an assignment given to me an Uni and we are not allowed to use databases. We are only allowed to used Generic List

Any idea what to do guys

Do you start with a blank list and add them using one of the forms?  If so I recommend you put this on one page and use something like knockout to keep them on the page.  Do you need to eventually store the list?

Yeah i start with a blank list and add to the list using one of the forms and then eventually stored whats on the list to a binary file. So i need a way to call just one single instance of the class that hold the list, so both form can use just that single instance

? any ideas.. Waiting thanks Guys

Yes as I said look at using knockout, this will let you create a model on screen without the need for postbacks etc.  

knockoutjs.com 

Hi guys i Have a web based application that contains a class called myList that create my collection list and handles adding of data to the collection list. Is it possible to declare a global instance of myList class tht will be created when the web application starts and will be accessible by any class that need to access the list in The myList Class. Thanks

Hi,

You can create this instance when page first load, and store this instance in session. When page post back , retrieve it from session.

You need to apply Object Oriented Programming principals here

use event for each add and delete or whatever you have than add these events in the interface and that inteface you can inherit anywhere and whenever you want to add or remove fire the event it will take care of the rest, thats the proper way

[RESOLVED] Are Ajax Data Templates deprecated

Hi,

this video displays a nice way to work with webservices and ajax:

http://www.asp.net/web-forms/videos/net-4/ajax/aspnet-4-quick-hit-ajax-data-templates

I want to do exactly what is being demonstrated in that video: get JSON data from a webservice in Jacascript and populate templates with the received data.

In the video a number of Microsoft Ajax scripts are being used. Most of them are hosted on the CDN. But the MicrosoftAjaxTemplates.js is only available as a beta version on the CDN (the video is from 2009, why would the .js file still be in beta?).

I read that the latest MicrosoftAjaxTemplates.js file is contained in the Ajax Contol Toolkit on Codeplex. But I can only find it in the Source (http://ajaxcontroltoolkit.codeplex.com/SourceControl/changeset/view/edf1fbcb2745#SampleWebSites%2fAjaxClientWebSite%2fScripts%2fMicrosoftAjax%2fMicrosoftAjaxTemplates.js)

Should I download that file and use it in my project? Or is the same file delivered via the Toolkit somehow?

Maybe there is a better way of getting done what I need?

TIA for any hints.

Regards

Tim

 

They are not being worked on, neither is jQuery Templates.

You can do templating and databinding using KnockoutJS.  It's super easy to get up and running:

http://knockoutjs.com/

Thank you Darrell, just the clue I needed. Website looks promising, I will try Knockout rather than messing with dying toolsets.

[RESOLVED] Which Ajax to use with Asp.net

Hello, I am starting a new Asp.net project soon for my company I work for. I was wondering if their is such a thing as the top 3 best Ajax toolkits to work with. I have used the Microsoft Ajax control toolkit, however I don't know if it is the best one to use. Can anyone give me their opinions on this?

There are AJAX controls from leading vendors like Telerik, Infragistics etc. Please download the trial version and see if it suits your needs:

Telerik - http://www.telerik.com/products/aspnet-ajax.aspx

Infragistics - http://www.infragistics.com/dotnet/netadvantage/aspnet.aspx#Overview

Component Source - http://www.componentsource.com/features/asp-net-ajax-controls/index.html

Hi,

you should also have a look at jQuery - http://jquery.com/

Use JQuery. It will load faster than ASP.net Ajax Tool kit.

To the JQuery developers, I was surprised to hear you recommend JQuery. I have used it, and like it alot. So are you telling me that it can be considered an equivalent replacement to AJAX. Especially with the capability to make asynchronous calls to the server? If so that is good news.

 

I have used Infragistics and Telerik, and dislike using yearly paid subscription plans. Especially when the products are not even that great.

jQuery is a good choice in an AJAX-approach. Of course you can make asynchronous calls to a server. For more information have a look at the jQuery AJAX API - http://api.jquery.com/category/ajax/

What about using the Microsoft Ajax control toolkit with JQuery? Is that okay. You see, I  would like to use the Asp.net GridView control with a tab control and this seems like it is problematic, unless you use the Microsoft Ajax control toolkit. So if I can use the Ajax control toolkit along with JQuewry, that might be a good choice.

Microsoft Ajax is essentially a dead technology, although it is still supported. The ASP.NET team fully support jQuery andmuch of their future work (eg Knockout) is based on jQuery. Telerik's Kendo (http://www.kendoui.com/?utm_source=telerik&utm_medium=index-divs&utm_campaign=box) is gaining interest, and is free, so that might be worth a look.

Having said all of that though, MS Ajax and the Toolkit is a perfectly valid solution, and may fit better with your skills.

Asyncronous data access

Dear fellow programmers:

I have the following: 2 asp.net (C#) apps, both of them 3-tiers apps, UI, Business Logic, and the DataAccess of both of them call the same webservice.

The apps are used on a classroom setting; one app is used to only log stuff to the database, students answering to multiple choice questions; the other app, is the teacher app, that only need to read those answers and see how many students choose option A, how many B, etc..

The challenge is that both apps run at the same time, so... the teacher needs to see live how the students are responding to the questions.

What I have so far is an AJAX timer that calls the BL layer, DA layer, WebService, every second checking the database, and it works fine. But my concern is that I am accessing this database too much, it is a hosted MySQL database (not in house), the app and web service also hosted with the same company, so the teacher just goes to one website, stundents go to other one and everything works fine...

But again... just that concern of too many calls to the database, are there any other options?

I was wondering how websites like facebook or gmail just "detect" when you received an email or somebody posts on your wall, because I need something similar.

Also... I do have control over everything here, so I am open to change the architecture of the WebService and/or the Website, however I want to stay 3-tier.

Thanks

search for SignalR

Haven't find any example that makes call to database.

Will appreciate if you have any.

Just thought of something, will apreciate your opinion:

What if, to the insertion task I add code to check the number of already inserted rows for the question, and since the number of students is known, use a simple comparison and when this number is reached trigger the "complete action"

Any other thoughts?

Again thanks so much

[RESOLVED] Property Owner & BuyerRenter in a estate agent system

Hi everyone,

I am building a estate agent sysytem. My system will allow buyers/renters placing an offer on the property. Then, the offer will be sent to property owners for accepting or rejecting. How to a property owner know when a buyer/renter place an offer on his/her property?. In addition, a buyers/renters need to know their offers accepted or rejected from property owners? Please give me some solutions to address these problems. Thank you very much.

Kind regards 

If you want to notify a person of some online event while the person is off line, the most common ways are email or text message.

Google/bing for many examples of how to send email or sms from asp.net web site.

apart from email and text, you can have on site notification systems - http://www.strathweb.com/2012/05/native-html5-push-notifications-with-asp-net-web-api-and-knockout-js/ 

Thanks,