BUG: Image Controls in UpdateProgess Control: Can not use FindControl() methods to get Image - image control returns null

There is a single UpdateProgress control on the page. as such:

<ajax:UpdateProgress  ID="UpdateProgress1" runat="server"   DisplayAfter="100" >

        <ProgressTemplate>
    
           <div style="border:2px solid #0099FF; background-color:#EFEFEF; padding:10px; width:200px; height:20px;">

              Updating Panel

           </div>

        </ProgressTemplate>

     </ajax:UpdateProgress>

 

This works...and the text is displayed

 

However, when adding a image instead such as:

<ajax:UpdateProgress  ID="UpdateProgress1" runat="server"   DisplayAfter="100" >

        <ProgressTemplate>
    
           <div style="border:2px solid #0099FF; background-color:#EFEFEF; padding:10px; width:200px; height:20px;">

                <asp:Image ID="ProgressImage" runat="server" ImageUrl='<%# String.Format("{0}", ResolveUrl("~/Images/admin/green_status.jpg"))%>' /> <--Bad Image URL need to set in Code Behind


           </div>

        </ProgressTemplate>

     </ajax:UpdateProgress>

 

With above: I can not access the Image Control from code-behind doing any number of nested, recursive, FindControl Methods.  However, prior to RC2 / RTM the code I used worked just fine to grab the image control and manipulate it.  I need to be able to access the image in code-behind so that I can properly set the url as the image paths are stored in the db using dynamically generated urls to access images on the file system or db.  If it the image url is not properly set then a 404 naturally gets injected into the page manipulation and stuff like gridviews dissapearing etc - occur - which is quite frustrating to troubleshoot as all kinds of unexpected behavior occurs (I have mentioned this many times about image not found injecting the actual 404 IIS generated script into a page). 

Code I use to find the control:

UpdateProgress1 = (UpdateProgress)GetOptionalControl(skin, "UpdateProgress1");
                if (UpdateProgress1 == null) { LE = LE + "UpdateProgress1,"; }
                //now get image


                updateImage = (Image)this.UpdateProgress1.FindControl("ProgressImage");
                 if (updateImage != null)
                 {
                     updateImage.ImageUrl = ResolveUrl("~/Communities/" + objSectionInfo.Skin + "/Images/progressbar_long_green.gif");
                     updateImage.AlternateText = "Loading in progress...";
                 }
                 else { LE = LE + "ProgressImage FindControl,"; }

or         

       updateImage = (Image)GetOptionalControl(skin, "ProgressImage");
                if (updateImage != null)
                {
                    updateImage.ImageUrl = ResolveUrl("~/Communities/" + objSectionInfo.Skin + "/Images/progressbar_long_green.gif");
                    updateImage.AlternateText = "Loading in progress...";
                }
                else { LE = LE + "ProgressImage skinLoad,"; }

or

updateImage = (Image)GetNestedControl(skin, "ProgressImage");
                if (updateImage != null)
                {
                    updateImage.ImageUrl = ResolveUrl("~/Communities/" + objSectionInfo.Skin + "/Images/progressbar_long_green.gif");
                    updateImage.AlternateText = "Loading in progress...";
                }
                else { LE = LE + "ProgressImage skinLoad,"; }


back end for the GetOptionalControl and GetNestedControl (which I use in scenarios where I have to find a control inside something like a multi-view where one has to dig into the control to explicitly load the child control).

   protected Control GetControl(Control skin, string controlID)
        {
            Control ctlFoundControl = skin.FindControl(controlID);
            if (ctlFoundControl == null)
            {
                throw new Exception("Could not find " + controlID + " in skin!");

            }
            return ctlFoundControl;
        }

        public Control GetNestedControl(Control skin, string controlID)
        {
            Control ctlFoundControl = null;
            try
            {
                ctlFoundControl = base.FindControl(controlID);
            }
            catch(HttpException)
            {
                ctlFoundControl = null;

            }
           return (ctlFoundControl != null) ? ctlFoundControl : GetNestedControl(skin.Controls, controlID);

        }

        public static Control GetNestedControl(ControlCollection col, string id)
        {
            foreach (Control c in col)
            {
                Control child = FindNestedControl(c, id);
                if(child !=null)
                    return child;


            }
            return null;
        }
        private static Control FindNestedControl(Control root, string id)
        {
            if (root.ID != null && root.ID == id)
            {
                return root;
            }

            foreach (Control child in root.Controls)
            {
                Control recurse = FindNestedControl(child, id);
                if (recurse != null)
                { return recurse; }
            }
            return null;

        }
        //*********************************************************************
        /// <summary>
        /// GetOptionalControl Method
        ///
        /// Retrieves a control from a skin. If the control cannot be
        /// retrieved, DOES NOT throw an exception.
        /// </summary>
        //*********************************************************************

        protected Control GetOptionalControl(Control skin, string controlID)
        {
            Control ctlFoundControl = skin.FindControl(controlID);
            return ctlFoundControl;
        }

 

The same code can find a Panel in the <UpdateProgress> but will not find the <asp: image.... />. And just for the record, I have a collapsible extender that I use the same syntax and able to load the control in code-behind and manipulate the url etc just fine.

 

 

 

With the bad url in the image control the "Get" process gets loaded twice.  This is on initial loading of page - being landed on for the first time

Here is with just text in the UpdateProgress Control (expected behavior click to load page)

12/6/2007 10:50:22 AM       /admin/Edit+Members/default.aspx       200 GET  

 22/6/2007 10:50:23 AM/       WebResource.axd       200       GET

With Image in UpdateProgress where the imageurl is bad: Single click to open page (same scenario as above)

12/6/2007 10:56:10 AM       /admin/Edit+Members/default.aspx       200 GET  

 22/6/2007 10:56:11 AM       /WebResource.axd       200       GET

12/6/2007 10:56:11 AM       /admin/Edit+Members/default.aspx       200 GET 

Note the duplicate /admin/Edit+Members/default.aspx - one before and after the WebResource.Axd Get

This is the wrong behavior...

This has to be a bug or something with the UpdateProgress? Again this code worked prior to the Release ....I just didn't realize it was broken because I typically do not have updates that would fall in the timer range I set


-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/6/2007 7:06:55 PM
asp.net.ajax-ui 9760 articles. 0 followers. Follow

12 Replies
2162 Views

Similar Articles

[PageSpeed] 13

bump... I'll just keep doing this until I get a real answer seeming I spend alot of time answering ALOT OF other questions - someone please pay attention....
-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 3:45:58 AM

Unfortunately, you cannot get to the controls - it gets added very late in the lifecycle (OnPreRender). Your best bet would be to create your own class that implements ITemplate and set your ProgressTemplate property to an instance of that class.

Chris Stewart has an example:

http://www.arcdeveloper.net/blogs/cstewart/archive/2006/04/11/95.aspx

Does that help?

Raj


Raj
http://weblogs.asp.net/rajbk/
0
rajbk
2/10/2007 6:06:31 AM

The post reference doesn't help (It was Atlas related and like I stated in my post / blog - it did work prior to Release version) however you are correct - the only solution is to create a custom control and embed it....

 

But I do take a stance that this should not be the case.. ScottGU's own blog pre-release (which is where I got my code and animations from)... the code was clip and pasted.

 

onsidering that the whole idea with ajac is using extenders....  honestly why should I incur such a issue even doing low level recursive control searching? A control is just a control why would it be 'hidden' even doing low level nbesting recursive searching? All I want to set is a image url.. simple in most programming aspects?

But thanks for the response....


-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 6:17:26 AM

dup


-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 6:29:50 AM
BTW i did try to get this on the pre-Render phase and failed... which by all accounts should of succeded......it is afterall the last bastion of the page lifecycle that you can maniulate a control... no go tho
-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 6:30:00 AM

It gets added in the OnPreRender stage, so you will find it if you override the page Render method (works for me) ... but even if you change anything at that stage, like you said, it becomes too late.

 I agree that this should have been designed like a normal templated control. I am not sure why it was done this way. Maybe due to time constraints.


Raj
http://weblogs.asp.net/rajbk/
0
rajbk
2/10/2007 6:43:35 AM
I totally agree and btw great blogs I found them a week or so ago - but they are excellent AND ON MY MUST VISIT LINK...     thanks for the contribution to the thread - Ilike you denoted ad what I know worked priot to the release version - there is an issue here.... and quite honestly if you have to wait to the on prerender phase on any control to do anything - it is way too late. but thanks for confirming where I could make it work but since this control is nested 2 series down I do not think I want to through the hassle considering in the RC releases it just worked by finding the control on the oninit cycle of the page  (perf wise you avoid doing anything on the page load anyways)..........Thanks again.......
-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 6:49:45 AM

Here is my code in the Render stage:

protected override void Render(HtmlTextWriter writer) {

Image Image1 = UpdateProgress1.FindControl("Image1") as Image;

if (Image1 != null) {

Image1.ImageUrl = "~/images/loading.gif";

}

base.Render(writer);

}


Raj
http://weblogs.asp.net/rajbk/
0
rajbk
2/10/2007 6:52:50 AM
I'll try that in the morning - I have already tried finding it in the prerender stage with no avail.. but I'll let some sleep and re-trying in the monring se if it solves the issue (although it should not be this difficult......) Again thanks....
-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 6:56:16 AM
Ideally, the UpdateProgress control should have the ProgressTemplate with attribute 

TemplateInstance

(TemplateInstance.Single)

This way you can directly access the inner controls without using FindControl just like the UpdatePanel. I am sure there is a reason why it was done this way. Maybe someone on the ASP.net team can answer this.


Raj
http://weblogs.asp.net/rajbk/
0
rajbk
2/10/2007 4:41:36 PM

I did try your suggestion - I still cannot get to the image control in the ProgressTemplate...

 

However - out of curiousity - I wanted to see if the control itself would be picked up if there was the image control inside the progress template and the same id control outside of the updateprogress control....

 

So interestingly enough the AjaxToolKitExtender finds it -

Server Error in '/SitesEasyTest' Application.

Multiple controls with the same ID 'ProgressImage' were found. FindControl requires that controls have unique IDs.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Multiple controls with the same ID 'ProgressImage' were found. FindControl requires that controls have unique IDs.

Source Error:

Line 211:            else
Line 212:            {
Line 213:                c = base.FindControl(id);  // Use "base." to avoid calling self in an infinite loop
Line 214:                Control nc = NamingContainer;
Line 215:                while ((null == c) && (null != nc))

Source File: D:\Ajax\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs    Line: 213

Stack Trace:

[HttpException (0x80004005): Multiple controls with the same ID 'ProgressImage' were found. FindControl requires that controls have unique IDs.]
   System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls) +220
   System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls) +280
   System.Web.UI.Control.EnsureNamedControlsTable() +57
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +106
   System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +64
   System.Web.UI.Control.FindControl(String id) +9
   AjaxControlToolkit.ExtenderControlBase.FindControlHelper(String id) in D:\Ajax\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:213
   AjaxControlToolkit.ExtenderControlBase.FindControl(String id) in D:\Ajax\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:241
   System.Web.UI.ExtenderControl.RegisterWithScriptManager() +104
   System.Web.UI.ExtenderControl.OnPreRender(EventArgs e) +17
   AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) in D:\Ajax\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:370
   System.Web.UI.Control.PreRenderRecursiveInternal() +77
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

 

So perhaps I'll have to do some learning and see what that path offset is in a control - the the toolkitextender can pick it up it means it can be done afterall....

 

 


-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 9:17:41 PM

Actually your prerender did work.  I had to change the img to <asp:image... I still think I am going to try find a way to adopt the control searching the extender classes use - but it did work.  Thanks Again....

 

Additional notes.

 

Exclude the scr="" in the <asp:image ... /> as it will not get updated instead when the proper url is set in the render it just adds it to the end of of the list of already established parametes...

 

 in other words there will be two src= parameters listsed when you view source... and if the first one is src="" or a bad image url - it will be what get loaded not the image url you set..on the render

 

 


-- jody
My Blogs on .Net 2.0 and Ajax
http://csk.wbcb.com
http://ArtbyJody.com
0
jodywbcb
2/10/2007 9:43:09 PM
Reply:

Similar Artilces:

superreview granted: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

superreview requested: [Bug 288906] Return null for MSAA name when no name explicitly set for HTML form control : [Attachment 179538] If no name explictly set for form control, use SetIsVoid(null)
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 288906: Return null for MSAA name when no name explicitly set for HTML form control https://bugzilla.mozilla.org/show_bug.cgi?id=288906 Attachment 179538: If no name explictly set for form control, use SetIsVoid(null) https://bugzilla.mozilla.org/attachment.cgi?id=179538&action=edit ...

Page and Control Flashing Using AJAX Control Toolkit Controls
Page and Control Flashing Using AJAX Control Toolkit Controls I'm using IE7 and the ASP.NET AJAX Control Toolkit.  I'm using two controls -- Accordion and CollapsiblePanelExtender.  I'm actually using 2 CollapsiblePanelExtenders, and the Accordion control is inside one of the panels for the CollapsiblePanelExtender (see the code below). The problem I'm seeing is that when I click an Accordion pane to open/close it or click the CollapsiblePanelExtender panel to open/close the panels, the controls and page flash while the animation is in progess.  Everything el...

ajax.net controls used in custom composite controls?
I am creating an events calendar that uses the accordion to display the events for the selected day.  The problem I'm having is that the accordion is not responding to any client side events.  I would really like to find a good "How to" article for building composite controls that incorporate an ajax.net control like the accordion....

Can i use Ajax CalenderExtender control with CreateUserWizard Control ?!
 Hi everyoneI'm trying to use  Ajax CalenderExtender control with CreateUserWizard Control  but when i run the page i can't see it in my pageplease help me to solve this problem   "ScriptManager1" runat="server"> "CreateUserWizard2" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Style="position: static" Width="450px" CreateUserBut...

What control do I use (or do I not use a control at all...)
Okay so here's the story so far. I am making a blog to be incorporated into a website. Well, I'm doing the blog from scratch. I'm using MySQL to source all the data via MySQL .NET/Connector. Now while developing the script, I used DataReader and Response.Write to show the blog topics. Now that it has come to put it under a design (I'm using a Master Page for that), I've hit the problem. Response.Write shows all the topics before any of the design elements could be incorporated. So that (more or less) is out of question. So next I looked into the data presentation controls. I looked up GridVi...

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Can a web user control access other controls? (Currently getting null reference errors)
Hi. I'm working on several administration web pages. A lot of them require me to enter in a mailing address. I created a user control called address. In another user control named organization, I have three address controls. When an organization loads, if there's an existing address ID, I'm trying to call a public address function called, loadAddress. When I do, I get the following error: System.NullReferenceException: Object reference not set to an instance of an object. at development.youthleadercert.com.share.ascx.organizationForm.Page_Load(Object sender, EventArgs e) in c:\document...

FileUpload control value gets clear when another control uses Ajax to retrieve data
Hello all, I have a web form.  There is a DropDownList control inside an update panel and the content is updated when a RadioButtonList control fires SelecteIndexChanged.  I also have another control, a FileUpload control.  If you select a file for the file upload control and then change the value RadionButtonList list control, the selected file in the FileUpload control disappears.How do I prevent RadioButtonList from clearing the value of the FileUpload control?Any help will greatly appreciated,  TIA,Dawa Below is the code: 1 <asp:RadioButtonList ID=&quo...

can't get records to update using grid view control or details control
Hi  I am using Visual Studio Web Developer 2005 Express and have set up a web page with a Grid View.  Everything works great, but when I click the EDIT link and make a change to a field, and then click UPDATE, it returns to the normal grid view form, but the change has not been made ??  I have the same proble using the details view object.  I do not get any errors, but the changes just do not seem to be made to the SQL table data. Any help would be greatly appreciated !   Thanks Chuck Hi Chuck, Can you verify you have DataKeyNames set in your GridView...

How to enable ajax (Use AJAX Controls) in my Web Control Library project
I have VS2005 with Ajax extended controls.   i have created a Web Control Library project, but i want to use ajax controls. is it possible.   I do not want to create a ajax enabled web site, but looking if any possible in my web control library project.   Please let me know and thanks in advance. D Hi, Yes. If you want to create User Control which contains a lot of web controls and Ajax control, you can create an User Control with Ajax Control to achieve it. If you want to create a Custom Control with Ajax, I suggest you build a new Extender. Please check the...

login control can i used to controll what data can user see it
i have a project with mulit company can i used login control to control what company user can see it and what user cant see it the company comes from databasethanks alot for any helphttp://www.feckra.com/blog/ first of all you should have a table in database database that contains (user_id, company_id,  password, auth_level). the auth_level can be used to grant specific content/page access to each user of each company. but, you need to override the authentication process as bellow.    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { L...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Error msg when refreshing a control... Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
HI, I'm getting this error msg when I do refresh to DDL like this: DropDownList DDLimg1 = (DropDownList)FormView1.FindControl("ddlIMG1");  //the dropdownlist is inside a formview.DDLimg1.DataBind(); What's the problem? How to fix it? Thanks. FindControl is case sensitive I believe.Solutions Architect Coden Enterpriseshttp://www.codenenterprises.com/iblog So, what to do to fix it? this is the error msg I'm getting.. Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control My FormView code: <Edit...

Web resources about - BUG: Image Controls in UpdateProgess Control: Can not use FindControl() methods to get Image - image control returns null - asp.net.ajax-ui

Resources last updated: 12/8/2015 1:51:34 PM