views:

42

answers:

0

I have an user control. I add dynamicly control to this control on its Page Init. This user control's parent Page's every postback, its page init works fine. After I added an different user control to Page. In Second User control, user select photos and uploads them with asyncfileupload control(AJAX). And I save all of them with a button at the end of Page.

In EveryPostBack Parent Page Load event works. If I dont select any photo from Second User Control, First User Control's Page Init event works fine when I click Save Button. But if I select a photo, first User Control dont work.

What is the problem?

a Part of mycode which is adding Photo User Control;

protected void AsyncFileUpload_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
        {
            string ID = (sender as AsyncFileUpload).ID;

            GetFile(int.Parse(ID[ID.Length - 1].ToString()), e);
        }

        private void GetFile(int index, AsyncFileUploadEventArgs e)
        {
            AsyncFileUpload fup = FindControl("AsyncFileUpload" + index) as AsyncFileUpload;
            if (!fup.HasFile)
                return;

            string fileName = Path.GetFileName(e.filename);
            string path = Server.MapPath("~/Temp/" + fileName);

            fup.SaveAs(path);

            Image img = FindControl("Image" + index) as Image;
            HiddenField hf = FindControl("HiddenField" + index) as HiddenField;
            if (hf.Value == "0")
                ScriptManager.RegisterClientScriptBlock(
                                this,
                                this.GetType(),
                                "HiddenField",
                                "top.$get(\"" + hf.ClientID + "\").value = '-1';",
                                true);

            ScriptManager.RegisterClientScriptBlock(
                                this,
                                this.GetType(),
                                "Image",
                                "top.$get(\"" + img.ClientID + "\").src = 'Temp/" + System.IO.Path.GetFileName(e.filename) + "';",
                                true);
        }