views:

130

answers:

1

Hi,

The code goes something like this:

protected bool IsOKToSend()
{
    bool IsOK = true;        
    lblErrorSending.Visible = false;
    if (txtUserName.Text == "" )
    { 
 lblErrorSending.Text = "Please enter your username before sending.";
 IsOK = false;
    }
    return IsOK;
}

    protected void btnSubmit_Click(object sender, EventArgs e)
{

    if (IsOKToSend())
    {
        adsUser.Insert();
        Response.Redirect("complete.aspx");
    }
    else
    {
        lblErrorSending.Visible = true;
    }
}

For some reason it doesn't work consistently on the live server. Keep in mind that it ALWAYS works on my local development machine and SOMETIMES (about 1 in 3 tries) works on the live machine. When it fails on the live server the page reloads and all viewstate are lost.

I have a default error catch in my webconfig file and the page is never redirected to the error page.

Consistent bug are easy to troubleshoot but something like this isn't.

Any idea on what could make this page sometime works and sometime not and/or why the viewstate aren't kept when it fails to work? Why am I not getting the same problem on my local machine?

I tried merging the two function to see if calling the external function was causing the issue but it didn't change anything unfortunately. Also, the value of IsOK does not seem to influence whether I'll get the bug or not.

I removed all the code in the page load function to make sure to troubleshoot correctly but I'm still getting the same issue.

Any idea will be appreciated.

Edit: I was gonna send this as is but I decided to try the following:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    bool IsOK = true;        
    lblErrorSending.Visible = false;
    if (txtUserName.Text == "" )
    { 
        lblErrorSending.Text = "Please enter your username before sending.";
        IsOK = false;
    }
    lblErrorSending.Visible = !IsOK;        
}

If I click a few times on the button the page does lose the viewstate value after a few tries but not always. So the main issue here appears to be a problem with the viewstate not working correctly all the time. Any idea?

Thanks.

+1  A: 

I will take a wild guess here and say you are not using sticky sessions in production and you have multiple web servers. But in development you have only one server. You are using load balancing and every so often you get kicked to a different server with a different machinekey in your maching.config. App goes boom.

Or this isn't it at all. :)

If it is the problem, you can turn off viewstate or sync the keys in your machine.config and the problem should go away.

Jason Slocomb
Thank you for the try. I am not using sessions on dev nor live. The live server is a single server so it can't be a load balancing issue unfortunately. Any more ideas please?
I can't see how this could be a code issue but I asked here just in case. When I started this project I tried using asp session but they were being lost by the host every few minutes. I'm guessing this is a similar host issue too so I opened a ticket with them. You get the green check for your help.
Good luck Tbate. I hope you get to the bottom of it.
Jason Slocomb