views:

71

answers:

3

I have a csv importroutine which imports my CSV values into Sitecore. After this proces is done i want to show the errors in an asp:literal. This is not working, and I think this is because i need an updatepanel for this in order to be able to update text after the first postback (the csv upload / import).

I made this:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel> 

and coded this:

 string melding = string.Format("Er zijn {0} objecten geïmporteerd.{1}", nrOfItemsImported, errors);

ViewState["Melding"] = melding;

And i have a button. On the onclick of this button I have:

        Literal literal = new Literal();
        literal.Text = (string)ViewState["Melding"];
        literal.ID = DateTime.Now.Ticks.ToString();

        UpdatePanel1.ContentTemplateContainer.Controls.Add(literal);
        PlaceHolder1.Controls.Add(literal);

When i now press the button i want to update the panel so that it will show my Literal with the errormsg on it. This however isn't happening. How can this be? I'm guessing it has something to do with my viewstate, i don't see keys on the viewstate after I press the button...


@Update:

I found the problem. I was storing information in a session, however the data for the key i was storing the information in was too large. This made the Session key empty. I was posting an empty string into my literal and therefore no information was shown. I am now looking for a better way to store my data and make it show in my updatepanel. I have tried Viewstate / Session / Cookies and none of it would work the way i wanted. When I am using a viewstate I am not able to store information. The viewstate (debugmode) shows count 0 and 0 keys ... Hope someone knows a good way to make sure that my errorstring (476kb) gets stored somewhere where i can easily post it to my updatepanel's literal.

A: 

In your code, have you tried UpdatePanel1.Update();? Even though you have added a control, you still will need to "trigger" the update to the update panel.

See here for a possible similar issue: StackOverflow

Tommy
I am using .update method yes. Thanks for the answer tho. I think it has smth to do with the viewstate. In the button click method when debugging i dont see any keys in the viewstate...
Younes
Do you the ViewState enabled? EnableViewState="True" should be set on the page.
Tommy
A: 

I tried this code and on click of button I am able to get the literal text on web page. Can you provide with some more details .

isthatacode
And yet again. I think it's my viewstate that is not working correctly. I can also get a Lit on my page with static text. I however want to store something (text) in the viewstate of this page and then transfer it to my error panel. And i see my viewstate is not filled with any info...
Younes
@Tommy, Younes - UpdatePanel1.Update() should not be called . As any postback event raised in the UpdatePanel will lead to AsyncPostback of UpdatePanel, which will update the panel anyway.
isthatacode
So, the UpdatePanel is working fine and you need to debug the Viewstate code now.
isthatacode
@isthatacode - your right, sorry about that. I thought his button was on the outside of the update panel :)
Tommy
+1  A: 

If you are using a FileUpload control, then you cannot use the UpdatePanel to asynchronously update the panel. The file upload is a synchronous event, so you'll need to update the Literal control on the page after the upload completed during the next Page_Load event.

Even Mien