PDA

View Full Version : [CLOSED] mixed ext.net asp.net cotnrols and postback



marco.morreale
May 30, 2012, 8:41 AM
Hi,

I am using an aspnet datalist to place data in multiple columns.
I would like reading user values when user presses "send data" button but my datalist has no item on postback.

Is there a way to get datalist hold his values on postback? Is there a different kind of postback I can use?

4302

Here is my code

markup


<ext:Window
ID="wGrigliaPoteri"
runat="server"
Title="Griglia dei poteri"
Icon="Application"
Height="500"
Width="800"
BodyStyle="background-color: #fff;"
BodyPadding="5"
Modal="true"
Hidden="true"
>
<Listeners>
<Show Handler="#{stPotere}.load();"></Show>
</Listeners>
<Content>
<table style="width:100%"><tr><td style="vertical-align:top; border: 1px solid lightgray; padding:10px">
<asp:DataList ID="dlGrigliaPoteriNeg" runat="server" Width="100%" ShowHeader="true"
RepeatColumns="3" ItemStyle-HorizontalAlign="Right" DataKeyField="ProductNumber" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true" HeaderStyle-Height="30px" >
<HeaderTemplate>Negativi</HeaderTemplate>
<ItemTemplate>
<table class="elGrigliaPoteri" >
<tr>
<td ><asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' /></td><td><ext:NumberField ID="nfGrigliaQuantity" runat="server" Width="60" MinValue="1" /></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
<td style="vertical-align:top; border: 1px solid lightgray; padding:10px">
<asp:DataList ID="dlGrigliaPoteriPos" runat="server" Width="100%" ShowHeader="true"
RepeatColumns="3" ItemStyle-HorizontalAlign="Right" DataKeyField="ProductNumber" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true" HeaderStyle-Height="30px">
<HeaderTemplate>Positivi</HeaderTemplate>
<ItemTemplate>
<table class="elGrigliaPoteri" >
<tr>
<td><asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Eval("Description") %>' /></td><td><ext:NumberField ID="nfGrigliaQuantity" runat="server" Width="60" MinValue="1" /></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td></tr></table>
</Content>
<Buttons>
<ext:Button ID="AddToCartFromGrid" runat="server" Text="Aggiungi al Carrello" Icon="CartAdd" >
<DirectEvents>
<Click OnEvent="AddToCartFromGrigliaPoteri" ></Click>
</DirectEvents>
<Listeners>
<Click Handler="#{gpBasket}.store.load();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
<asp:ObjectDataSource ID="odsGrigliaPoteriNeg" runat="server" TypeName="renosistemi.it.Shared.EXTJSWebService" SelectMethod="getPoteriProdottoListNeg"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsGrigliaPoteriPos" runat="server" TypeName="renosistemi.it.Shared.EXTJSWebService" SelectMethod="getPoteriProdottoListPos"></asp:ObjectDataSource>






codebehind



protected void AddToCartFromGrigliaPoteri(object sender, DirectEventArgs e)
{
Guid? basketID = new Guid(Request["Id"]);
int count = 0;
using (renosistemi.it.Shared.EXTJSWebService myWS = new Shared.EXTJSWebService())
{
foreach (DataListItem myItem in dlGrigliaPoteriNeg.Items)
{
Ext.Net.NumberField nfGrigliaQuantity = (Ext.Net.NumberField)myItem.FindControl("nfGrigliaQuantity");

int quantity = Convert.ToInt32((double)nfGrigliaQuantity.Value);
if (quantity > 0)
{
string productID = (string)dlGrigliaPoteriNeg.DataKeys[myItem.ItemIndex];
myWS.insertBasketLine(basketID, productID, quantity);
count++;
}
}
foreach (DataListItem myItem in dlGrigliaPoteriPos.Items)
{
Ext.Net.NumberField nfGrigliaQuantity = (Ext.Net.NumberField)myItem.FindControl("nfGrigliaQuantity");

int quantity = Convert.ToInt32((double)nfGrigliaQuantity.Value);
if (quantity > 0)
{
string productID = (string)dlGrigliaPoteriNeg.DataKeys[myItem.ItemIndex];
myWS.insertBasketLine(basketID, productID, quantity);
count++;
}
}

}

GridPanel gpBasket = X.GetCtl<GridPanel>("gpBasket");
if (gpBasket != null)
{
var store = gpBasket.GetStore();
store.Reload();
}
X.Msg.Notify("Ok", string.Format("Inseriti {0} articoli", count)).Show();
wGrigliaPoteri.Hide();

}

Vladimir
May 30, 2012, 10:04 AM
I guess you need to rebind DataList to get controls but i am not sure about it (i don't know how is implemented DataList). How do you read values if replace Ext.Net field by ASP.NET TextBox?

Imho, In your case it is better to read values directly from Request

marco.morreale
May 30, 2012, 10:23 AM
If I rebind the datalist I lose user data input (textbox values).

I tried to replace ext.net numberfileds with asp.net textbox with no result.

It looks complex reading data from request because I need to bind that to product codes wich are stored on datalist items.

M

Vladimir
May 30, 2012, 10:26 AM
Try to rebind in Page_Init (before LoadPostData logic will be executed)