1

I have an update panel with postbacktriggers and the label that I plan to update is in the navbar, which is not included in the UpdatePanel where the triggers are located. Below is the structure of that code:

<asp:Label ID="totalScorecardsLabel" runat="server"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnGenerateScorecard" />
                        <asp:PostBackTrigger ControlID="exportPDFbtn" />
                        <asp:PostBackTrigger ControlID="generateNewBtn" />
                    </Triggers>
                    <ContentTemplate>
                             divs.. etc
                    </ContentTemplate>
    </UpdatePanel>

On the other hand, I have a click event for exportPDFbtn that adds entries to a list, therefore incrementing the list size.

int totalScorecards = loadTest1.Count + loadTest2.Count + loadTest3.Count + loadTest4.Count;
totalScorecardsLabel.Text = totalScorecards.ToString();

The totalScorecards Label is outside the UpdatePanel. I've set it to 0 on Page_Load if (!IsPostBack).

protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                   init();//initialize all lists etc
                   int totalScorecards = 0;
                   totalScorecardsLabel.Text = totalScorecards.ToString();
    }
}

After clicking the exportPDFbtn, I expect a increment change in the label. After that I plan to click the generateNewScorecardbtn, and expect the totalScorecards number to carry on postbacks.

But the problem is that the label is still on 0 even though elements are successfully added to the lists in the exportPDF clickEvent (used breakpoints to discover if it really adds to the lists). I also use Server.Transfer("Scorecards.aspx") for the generateNewScorecardbtn.

Any help would be appreciated. Thanks!

JPaulPunzalan
  • 417
  • 1
  • 6
  • 20

2 Answers2

1

Put it into another Update Pannel and use Update() method
https://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.update(v=vs.110).aspx

Saurabh
  • 1,505
  • 6
  • 20
  • 37
  • Is the constructor required? What does `ViewState["LastUpdate"] = value;` do? Could you provide a snippet of your code idea? – JPaulPunzalan Mar 10 '17 at 02:13
  • ViewState["LastUpdate"]=value is used here to update the panel every five seconds here , i dont think you need that code. You just need to invoke UpdatePanel.Update() method – Saurabh Mar 15 '17 at 06:26
0

It wont work if its outside the panel. You need to put label in a separate update panel and it will work then.

Mohammad
  • 132
  • 5
  • I only have to put it inside another update panel? What else? – JPaulPunzalan Mar 08 '17 at 06:28
  • How about the UpdateMode property? – JPaulPunzalan Mar 08 '17 at 06:30
  • keep the UpdateMode property 'conditional' – Mohammad Mar 08 '17 at 06:39
  • It is not working. Just like the question in this [question](http://stackoverflow.com/questions/18778623/unable-to-update-label-outside-update-panel) – JPaulPunzalan Mar 08 '17 at 07:27
  • remove the 'UpdateMode' property from your update panel with triggers. but keep it 'conditional' on the new panel added. hope it'll work – Mohammad Mar 08 '17 at 07:35
  • I've tried that one also but still no luck. The label is still `0` despite the postbacks. – JPaulPunzalan Mar 08 '17 at 07:38
  • In that case you should use jquey+ajax to assign value to label after your calculations.. or use a hidden field in your update panel (old one) and then on your button event assign label the value of hidden field. – Mohammad Mar 08 '17 at 07:42
  • I think there is a pageLoad issue, my lists would only increment once the clickevent has been called. After the next postback (Generate New Scorecard) button, it goes to the empty form page. Once I generate a new card and then export, the list increment from 0 to 1 again. – JPaulPunzalan Mar 08 '17 at 07:50
  • then you should use hidden field in your panel.Hidden field doesn't reset on postbacks – Mohammad Mar 08 '17 at 08:05
  • Are there any other solutions so that my globally declared lists won't keep on going back to having no elements after postbacks? I am also storing the score results of each card generated.. – JPaulPunzalan Mar 08 '17 at 08:17