debonaire
debonaire

Reputation: 319

Label text value does not change after executing an elapsed event callback

Hi all I'm still new to the c# events and timers but it seems I have a bug that baffles me despite following seemingly working code online. I have a simple search function that is triggered after a timer elapses. Before that function triggers I set the result title to "Search in progress..." and at the end of the process i expect it to change to "1152 results found". But the label doesn't change eventhough in debug i hit the code sets it and i even see that the searchresultTitle.Text value is changed and the "list" actually contains 1152 items. The website just doesnt reflect it, is there something wrong with the way I setup the timers or am I missing something?

protected void StartSearchClick(object sender, EventArgs ev)
{
    String textVal = Request["SearchBox"];
    textVal = textVal.Replace('*', '_');//to support * as wildcard
    String publicChoice = PublicChoice.SelectedValue;
    int iChoiceVal = 1;
    Int32.TryParse(publicChoice, out iChoiceVal);

    SearchResultTitle.Text = "Search in progress...";
    System.Timers.Timer aTimer = new System.Timers.Timer(1000);
    aTimer.Elapsed += (s, e) => ReadPublishedLessons(textVal, iChoiceVal);
    aTimer.AutoReset = false;
    aTimer.Start();
}

private void ReadPublishedLessons(string namePart, int iPublic)
{
    //null check
    if (namePart == null)
        return;

    eon.LessonInfo[] list = WsAdmin.GetLessonList(namePart, iPublic);
    SearchResultTitle.Text = list.Length + " results found";
}

Upvotes: 0

Views: 86

Answers (1)

debonaire
debonaire

Reputation: 319

Answered by Bharadwaj in the comments...

In case of asp.net, the html is sent back to the client side only after a post back or a partial post back. At the end of your event trigger call, the html which is ready is already reached to the client with Search in progress... message. But when you try to change the value of label, it is changing and it is still at server only. – Bharadwaj Jul 15 '16 at 4:45

Upvotes: 1

Related Questions