• Hi Guest: Welcome to TRIBE, the online home of TRIBE MAGAZINE. If you'd like to post here, or reply to existing posts on TRIBE, you first have to register. Join us!

cSharp Question(s)

stir-fry

TRIBE Member
Hi All.

We have started using c# in my office, but I am a vb programmer by nature.
I have a question about a simple practice that i'm sure any of you can answer.

The scenario is that I have a form for entering Line Items (requisitions). After the user enters the data for each line item, I want to save the info somewhere in memory until they finally post the info back to the server.

In VB, i'd either create a disconnected ador.recordset, or create a collection class to store the info.

What is the accepted method in c# for storing this kind of data?

I just came across a Generics sample, is this what I should be looking at?
 

stir-fry

TRIBE Member
thanks for the info.. i ended up creating a class with public gets/sets for all of the information i needed to store and then stored the info list<> using the new generics framework.
our consultant also suggested using datasets, but since the generics collection is serializable it's basically the same thing.
 

stir-fry

TRIBE Member
Can someone please help me..

i need to raise event(s) from an asp.net usercontrol and consume the events in the parent webpage.. the examples i have found so far are really hard to follow.. can anyone give me a quick example of how to accomplish this?

i basically have 2 buttons, add and change in the usercontrol, and i want the parent to react to these 2 buttons when they are clicked.

thanks in advance.
 

stir-fry

TRIBE Member
Okay, here's what I have so far..

(inside the user control)

public class AddItemEventArgs : EventArgs
{
private readonly string stockNumber;

//Constructor.
//
public AddItemEventArgs(string stockNumber)
{
this.stockNumber = stockNumber;
}

public string StockNumber
{
get { return stockNumber; }
}
}

// Delegate declaration.
//
public delegate void AddItemEventHandler(object sender, AddItemEventArgs e);
public event AddItemEventHandler Click;

protected virtual void OnClick(AddItemEventArgs e)
{
if (Click != null)
{
Click(this, e);
}
}

protected void btnSaveLineItem_Click(object sender, EventArgs e)
{

// what do i put in here to actually raise the event?
}


(inside the main webpage)


(this line is in the form load.. correct?)
ReqInput1.Click += new ReqInput.AddItemEventHandler(MySubmitButtonClick);

//is this all i need to trap the event in the main form?
private void MySubmitButtonClick(object sender, ReqInput.AddItemEventArgs e)
{
if (e.StockNumber != null)
{
Console.WriteLine("Finally!");
}
}

 
tribe cannabis accessories silver grinders

Liquidity

TRIBE Member
what was the solution? could you not the page object from the control, and reach the page code-behind that way?
 

stir-fry

TRIBE Member
i forget the exact code, as it's at work, but i basically just had to call the OnClick() and pass it all of the parameters.
i'll put the code up tomorrow
 

stir-fry

TRIBE Member
Liquidity said:
what was the solution? could you not the page object from the control, and reach the page code-behind that way?
The thing is, we need to write these components as stand-alone components.. so raising events and letting the parent consumer handle them was the only way to go for us..

here's what I ended up doing to accomplish this.

(inside the control)
Code:
public class SaveItemEventArgs : EventArgs
    {
        private readonly string shipToLocation;
    
        public SaveItemEventArgs(string shipToLocation)
        {
            this.shipToLocation = shipToLocation;
        }
        public string ShipToLocation
        {
            get { return shipToLocation; }
        }
    }

    public delegate void AddItemEventHandler(object sender, SaveItemEventArgs e);
    public event AddItemEventHandler Click;
    
    protected virtual void OnClick(SaveItemEventArgs e)
    {
        if (Click != null)
        {
            Click(this, e);
        }
    }

    protected void btnSaveLineItem_Click(object sender, EventArgs e)
    {
        sShipToLocationCode = "BLAH";
        SaveItemEventArgs eventAddItem = new SaveItemEventArgs(sShipToLocation);
    

      OnClick(eventAddItem);
    }

(In the Parent Control)
Code:
    (page_load)
    ReqInput1.Click += new ReqInput.AddItemEventHandler(MySubmitButtonClick);
    
private void MySubmitButtonClick(object sender, ReqInput.SaveItemEventArgs e)
    {        
        if (e.ShipCode != null)
        {
            Console.WriteLine("Finally, it worked!");
        }
    }

In my case, I wanted information to come back with the click, which is why i created the SaveItemEventArgs that inherits from EventArgs, but you can skip this step if you don't need to send any information back.
 
Top