开发者

Need to upload file, and use it in the pre-init event

开发者 https://www.devze.com 2023-01-14 03:16 出处:网络
As it states, I need to upload a file, and then use it in the pre_init event of a second page. Server lifecycle prevents this (as pre_init happens before the event handlers), that\'s fine, so the only

As it states, I need to upload a file, and then use it in the pre_init event of a second page. Server lifecycle prevents this (as pre_init happens before the event handlers), that's fine, so the only way I can see around is to use page1 to upload the file, then do a response.redirect to the page2 where I can use the file in the pre_init. But this seems a)convulted, and b)needs me to pass the uploaded filename through to the second page.

Is开发者_如何学C there anyway around this, or am I going to have to like and lump it?

(I need the pre_init event to add steps to a wizardcontrol, and deserialise the file to get the objects to add to it).

Thanks


You should be able to use Request.Files directly from pre_init:

protected void Page_PreInit(object sender, EventArgs e)
{
    HttpPostedFile file = Request.Files["IDOfFileUploadControl"];
}


Cross-Page posting seems like a solution. You can get the FileUpload control from previous page like this:

if (Page.PreviousPage != null)
{
    FileUpload prev = 
        (FileUpload)Page.PreviousPage.FindControl("FileUpload1");
    if (prev != null)
    {
        // Operations.
    }
}

I haven't tried if it works in Pre_Init event but it worth trying.

For more information about Cross-Page Posting:

http://msdn.microsoft.com/en-us/library/ms178139.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消