1

(I'm running on Visual Studio 2008 (ASP:NET 3.5) with the development web server)

I have the an asp.net page where:

There is a SliderExtender control inside an UpdatePanel.

Server side I'm catching the Changed event for the slider.

User can change slider value and everything work fine.

The problem

The user can use the arrow to change slider's value but when he leaves the arrow down for a while, a "Invalid ViewState" exception raises.

Invalid viewstate. 
Client IP: 127.0.0.1
Port: 
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; .NET4.0C; .NET4.0E)
ViewState: /wEPDwXJja...

I've tried on Chrome an IE8 with same results.

I understand it happens because the server side Changed method is called again and again and time comes when the server processing speed is beaten by the incoming calls.

The question

How can I avoid this problem to happen?

What have I tried?

  • Most popular suggestions on this question.
  • Override page render to put ViewState at top.
  • Stablish a ViewStateUserKey.
  • Disable form till window loads.
  • Setting a machine key.

EDIT

This is the code:

<asp:TextBox runat="server" ID="txtSlider" AutoPostBack="true" Text="100" OnTextChanged="txtSlider_TextChanged"></asp:TextBox>
<asp:SliderExtender ID="sldSlider" Decimals="0" TargetControlID="txtSlider" Length="50" 
            BoundControlID="lblProporcion" runat="server" Minimum="0" Maximum="100" >
        </asp:SliderExtender>

protected void txtSlider_TextChanged(object sender, EventArgs e)
{            
    //Server processing, UpdatePanel's update....
}

When the user move the slider changing its value, txtSlider's text property changes this raising the txtSlider_TextChanged event. I think I could use a HiddenField to store the last time I postback and use that at client side to define if txtSlider postbacks or not (if at least 500ms has passed then go ahead and postback).

I'm working on that last approach, I'll let you know if I manage to solve this thing.

Community
  • 1
  • 1
daniloquio
  • 3,822
  • 2
  • 36
  • 56
  • I would introduce some sort of throttling on the client side- i.e only update/call the server on for example mouseup- so the slider would change values but it wouldn't actually call the server until the user has let go of the button/mouse. Or just cache the values of the slider client side? Is this possible? – leon Sep 13 '12 at 20:44
  • @leon I'm calling the server method only on mouseup, the problem is when the user uses the keyboard's arrow because then the changed event raises for each unit. I need to call the server method so your second suggestion is not an option sadly. Thanks though! – daniloquio Sep 13 '12 at 21:06
  • what about using [onkeyup](https://developer.mozilla.org/en-US/docs/DOM/element.onkeyup)? so only call server _after_ user has lifted off the arrow key? you got the server side code too? – leon Sep 14 '12 at 11:04
  • @leon when the user has the key down SliderExtender start changing its value one unit at a time and that change txtSlider's text property raising the server method. I think I can't control the keydown and keyup events to change that order. – daniloquio Sep 14 '12 at 13:34
  • Do you need to handle the server side event or is it possible to use logic on the client instead. Possibly using a custom AJAX call if you do need values from the server. – alhalama Sep 19 '12 at 02:35
  • @alhalama yes I need to handle that server side. – daniloquio Sep 20 '12 at 13:37

1 Answers1

-1

I no longer have that problem but neither I solve the question. I'm catching the Invalid ViewState exception so the user don't notice any problem and everything works smoothly.

I'm doing it on global.asax:

protected void Application_Error(object sender, EventArgs e)
{
    Exception exc = HttpContext.Current.Server.GetLastError().InnerException;
    if (exc != null)
    {
        //register the exception on error log table
    }
}

If someone post a real answer to this question I'll unmark this one inmediatelly.

daniloquio
  • 3,822
  • 2
  • 36
  • 56