Search code examples
c#asp.netweb-applicationsenterprise-web-library

What use is initUserDefaultOptionalParameterPackage in EWL?


I'm using EWL and I have an EwfPage and when I type partial in the Info class I see:

partial void initDefaultOptionalParameterPackage( OptionalParameterPackage package )

and

partial void initUserDefaultOptionalParameterPackage( OptionalParameterPackage package )

I don't really see what they're used for. They also sound similar and I'm wondernig what the difference between them is.


Solution

  • They are both used if you want an optional parameter to default to something other than the default value of its C# data type. There are two significant differences:

    • initUserDefaultOptionalParameterPackage is called only when you are creating an Info object for the page; it is not called when the page is requested. If a request is made without a parameter value in the URL, the framework will fall back to the value specified in initDefaultOptionalParameterPackage or the data type default.
    • You can access AppTools.User from initUserDefaultOptionalParameterPackage if you meet the conditions specified in the doc comment for AppTools.User.

    An example of when you might use initUserDefaultOptionalParameterPackage is a page that should default to showing information for the currently logged-in user but has a select list or something that lets you look at information for a different user.