PDA

View Full Version : [CLOSED] Help saving values from GridPanel



pmnicaragua
Oct 26, 2013, 7:23 PM

Daniil
Oct 28, 2013, 6:16 AM
Hi @pmnicaragua,

Are these properties just the Page's ones?


public List<EstudioRealizado> LEstudioR;
public List<OtroEstudio> LOtroEst;




How do you save it to a database? In an individual request?

One request - SubmitSelectionGrdEstudios - for saving data to those Page's variables, another request - to save it to database?

If so, I think the problem is the fact that the Page's variable are not maintained across requests. This example demonstrates it.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public string TestProp;

protected void Set(object sender, DirectEventArgs e)
{
this.TestProp = "Hello!";
}

protected void Get(object sender, DirectEventArgs e)
{
X.Msg.Alert("", this.TestProp).Show();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Set" OnDirectClick="Set" />

<ext:Button runat="server" Text="Get" OnDirectClick="Get" />
</form>
</body>
</html>


It might be best to save the data from the Store to the database in the single request.

pmnicaragua
Oct 28, 2013, 4:17 PM
Hi @pmnicaragua,

Are these properties just the Page's ones?


public List<EstudioRealizado> LEstudioR;
public List<OtroEstudio> LOtroEst;




How do you save it to a database? In an individual request?

One request - SubmitSelectionGrdEstudios - for saving data to those Page's variables, another request - to save it to database?

If so, I think the problem is the fact that the Page's variable are not maintained across requests. This example demonstrates it.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public string TestProp;

protected void Set(object sender, DirectEventArgs e)
{
this.TestProp = "Hello!";
}

protected void Get(object sender, DirectEventArgs e)
{
X.Msg.Alert("", this.TestProp).Show();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Set" OnDirectClick="Set" />

<ext:Button runat="server" Text="Get" OnDirectClick="Get" />
</form>
</body>
</html>


It might be best to save the data from the Store to the database in the single request.

Hello Daniil,

Those are simply objects that store the info from the grids, and the thing is that there is only one huge "Save method" that gets all the info from the 8 tabs, i have to say that all tabs are in the same page, they look just like a wizard form that you guys have on http://examples2.ext.net/#/Layout/CardLayout/Basic/.

And yeah, that seems to be the problem, values of variables are not mantained, is there a way to overcome this obstacle? Like with Session Variables or ViewState?

pmnicaragua
Oct 28, 2013, 6:18 PM
Hello Daniil,

Those are simply objects that store the info from the grids, and the thing is that there is only one huge "Save method" that gets all the info from the 8 tabs, i have to say that all tabs are in the same page, they look just like a wizard form that you guys have on http://examples2.ext.net/#/Layout/CardLayout/Basic/.

And yeah, that seems to be the problem, values of variables are not mantained, is there a way to overcome this obstacle? Like with Session Variables or ViewState?

Ok, so after reading a lot sessions and viewstate lectures, i ran into the solution, all i had to do was to declare a few session variables after saving my grid into the object, like this:


Session["Grid1"] = ListWithValues1;

Then on the save method, the one that actually has to recover all of the objects previously saved all i had to do is to call my session variable previously created and cast it to the right variable type


PublicVariableList = (PublicVariableList<>)Session["Grid1"];

Actual code goes like this:
In the method that stores into the database:

LEstudioR = (List<EstudioRealizado>)Session["EstudiosRealizados"];

In the method that stores data into the object



protected void SubmitSelectionGrdEstudios(object sender, DirectEventArgs e)
{

string json = e.ExtraParams["Values"];

string TipoEstudio;
string Institucion;
string TipoCertificado;
DateTime FechaInicio;
DateTime FechaFinal;

List<string> resultado = new List<string>();

if (string.IsNullOrEmpty(json))
{
return;
}

foreach (XmlNode row in xml.SelectNodes("records/record"))
{
EstudioRealizado EstudioR = new EstudioRealizado();

TipoEstudio = row.SelectSingleNode("TipoEstudio").InnerXml;
Institucion = row.SelectSingleNode("Institucion").InnerXml;
FechaInicio = Convert.ToDateTime(row.SelectSingleNode("FechaInicial").InnerXml);
FechaFinal = Convert.ToDateTime(row.SelectSingleNode("FechaFinal").InnerXml);
TipoCertificado = row.SelectSingleNode("TipoCertificado").InnerXml;

try
{
EstudioR.TipoEstudio = Convert.ToInt32(TipoEstudio);
EstudioR.TipoCertificado = Convert.ToInt32(TipoCertificado);
EstudioR.Institucion = Institucion;
EstudioR.FechaInicial = FechaInicio;
EstudioR.FechaFinal = FechaFinal;
LEstudioR.Add(EstudioR);
}
catch (FormatException fe)
{
Mensajes.escribirTopRight("Exception", "Warning", Ext.Net.Icon.Information);
}
}

Session["EstudiosRealizados"] = LEstudioR;
}

This way i can preserve my information across server requests, hope this is useful to others with the same problem, mark this as closed please.

Daniil
Oct 29, 2013, 10:32 AM
Yes, the Session object can be used to store the data across the different requests. But please note that the Session uses cookies (by default). Do you need all that data in the cookies? Do you really need that intermediary store? Well, if you have to make different requests for each Store/GridPanel to save its data then there is no principal alternative. But are you really restricted to save it in different requests?

As far as I can understand your scenario it is:

1. Wizard step #1
2. A user fill out a GridPanel and goes to the Wizard step #2
3. Here you save the data filled out on the step #1
4. Wizard step #2
5. A user fill out a GridPanel and goes to the Wizard step #3
6. Here you save the data filled out on the step #2
7. etc.

Has I got it right? If yes, then is there any chance to save all the data at the final step? It should be possible if, as you said, all the GridPanels are on the same page.

Or, maybe, you would like not to lose the data filled out in the previous Wizard steps if something crashes? Well, yes, it makes sense.

Daniil
Oct 29, 2013, 12:26 PM
The thread looks related to this one:
http://forums.ext.net/showthread.php?27004