Preupload Validation

Thread is closed for posting
4 posts, 1 answers
  1. Kyle
    Kyle avatar
    9 posts
    Member since:
    Aug 2010

    Posted 14 Oct 2010 Link to this post

    Is it possible to do a preupload validation that requires server-side code?

    For example, I want to make sure that a variable is in session before the upload continues.  We have users that go thru our upload process, get to the end (which removes all session variables), then they click Back on their browser and try to do another upload.  Doing so causes a NullReferenceException.

    I'd like to check to see if the session variable exists.  If it does, allow the upload to continue.  If not, forward them to a new page telling them their session has expired.

    Any ideas would be greatly appreciated.

    Thanks,
    Kyle
  2. Answer
    Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 14 Oct 2010 Link to this post

    Hello Kyle,

    If they are pressing the back button, you can't do a server-side check for the variable since the broswer is using cached version of your page, so no postback is made. You could most add an Ajax call in that page, which would run when the page is loaded, since that should be called during this kind of situation and redirect them to the page saying their session has expired.

    To do what I just described, add a RadAjaxManager control on the page and then use its ajaxRequest client-side method to make an ajax call. In the code-behind handle the AjaxRequest event and redirect them if the session doesn't exist.

    So something like this:

    JavaScript:

    $telerik.$(document).ready(function(){$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("CheckSession");});

    Code-Behind:

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "CheckSession")
            {
                // check session code goes here
      
                // redirect user if it fails
                RadAjaxManager1.Redirect("SessionExpired.aspx");
            }
        }

    I hope that helps.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kyle
    Kyle avatar
    9 posts
    Member since:
    Aug 2010

    Posted 14 Oct 2010 Link to this post

    That's a good idea.  I didn't think about doing a check at page load via AJAX.  I was thinking about using an AJAX call to a WebMethod when the user clicked Upload.  I guess that's what happens when you have blinders on.

    The other thought I had was to try setting Response.Cache.SetCacheability(HttpCacheability.NoCache);  I haven't tested this yet, but I'm going to try that first.

    Thanks for the help!
  5. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 15 Oct 2010 Link to this post

    Yeah, I was going to suggest setting a response header, but I thought you wanted the ability to use the back button. If you want to prevent them from pressin back, I would set the Expires response header to a day or hour in the past or the current time, I'm not really sure, but you can test it out, so the browser will not try load the page again. It will just say the page expired, like you see on some governement or ticket web sites.

    I hope that helps.
Back to Top