asp.net - using control states in server control -


i have server control trying save properties control states reason properties not persisting across partial postbacks.

the psuedo code follows:

public class fileupload     inherits scriptcontrol     implements inamingcontainer, ipostbackeventhandler      public property newfileext() string                     dim foundlist string = directcast(viewstate(me.uniqueid & "_fileext"), string)             if foundlist isnot nothing                 return foundlist             else                 return string.empty             end if         end         set(byval value string)             viewstate(me.uniqueid & "_fileext") = value         end set     end property      protected overrides sub oninit(byval e system.eventargs)                    mybase.oninit(e)         page.registerrequirescontrolstate(me)     end sub     protected overrides function savecontrolstate() object         dim controlstate(6) object          controlstate(0) = mybase.savecontrolstate()         controlstate(1) = newfileext           return controlstate     end function     protected overrides sub loadcontrolstate(byval savedstate object)         dim controlstate() object         controlstate = ctype(savedstate, object)         mybase.loadcontrolstate(controlstate(0))          newfileext = ctype(controlstate(1), string)            end sub  end class 

on control asyncfileupload ajaxcontroltoolkit control , button. have event upload complete:

protected sub saveuploadedfile(byval sender object, byval e ajaxcontroltoolkit.asyncfileuploadeventargs) handles asyncfileupload.uploadedcomplete     newfileext= "some value" end sub  protected sub bntselectresults_click(byval sender object, byval e eventargs) handles bntselectresults.click     if (newfileext= "")        'this returns empty     end if end sub 

so, uploadedcomplete complete should set controls state. then, when user click button should read it. through debugging, can see set correctly in uploadedcomplete event null when read. due cycle of page or something?

thanks jason

edit

i traced out path how page cycle running:

  1. user clicks async file upload control's browse button , selects file. causes upload process start

    a. oninit gets called

    b. loadcontrolstate gets called

    c. onload gets called

    d. asyncfileupload.uploadedcomplete gets called , set newfileext property here.

    e. savecontrolstate gets called. newfileext set here properly

  2. user clicks button on control initiates partial postback/update of update panel a. oninit gets called

    b. loadcontrolstate gets called. can see newfileext property not set

    c. onload gets called

    d. buttons click event gets called , property read (which no longer set)

    e. savecontrolstate gets called , cycle ends

so, best can tell, asyncfileupload application has issues viewstates/controlstates. ended just using sessions.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -