TextBoxWatermarkExtender crashes UpdatePanel

Last post 08-03-2006 2:03 AM by jyoti22apr. 9 replies.

Sort Posts:

  • TextBoxWatermarkExtender crashes UpdatePanel

    05-09-2006, 11:07 AM
    • Member
      72 point Member
    • dirkb
    • Member since 01-06-2006, 11:35 AM
    • Germany
    • Posts 15

    Hi,

    this took me several hours now to cut down the problem in my complex atlas application.

    If I add a TextBoxWatermarkExtender and a UpdatePanel to my site and like to show/hide the UpdatePanel from C# code behind I get a JavaScript Error "Sys.Application.findObject(...)' is Null "

    To reproduce this you have to follow these steps:

    1. Create a new Atlas Web
    2. My page is called Default2.aspx and looks like this:

    <%

    @ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

    <%

    @ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <

    html xmlns="http://www.w3.org/1999/xhtml" >

    <

    head runat="server">

    <title>Untitled Page</title>

    </

    head>

    <

    body>

    <form id="form1" runat="server">

    <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering=true>

    </atlas:ScriptManager>

    <atlasToolkit:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server">

    <atlasToolkit:TextBoxWatermarkProperties TargetControlID="TextBox1" WatermarkText="my watermark" />

    </atlasToolkit:TextBoxWatermarkExtender>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>&nbsp;

    <atlas:UpdatePanel ID="UpdatePanel1" runat="server">

    <ContentTemplate>

    UpdatePanel1

    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Show/Hide Panel</asp:LinkButton>

    <atlas:UpdatePanel ID="UpdatePanel2" runat="server">

    <ContentTemplate>UpdatePanel2</ContentTemplate>

    </atlas:UpdatePanel>

    </ContentTemplate>

    </atlas:UpdatePanel>

    </form>

    </

    body>

    </

    html>
    1. The code behind looks like this

    protected void LinkButton1_Click(object sender, EventArgs e)

    {

    if (UpdatePanel2.Visible)

    UpdatePanel2.Visible =

    false;

    else

    UpdatePanel2.Visible =

    true;

    }

     

    If you run the site it is possible to hide the UpdatePanel2 for exact one time. If You click the link a 2nd time it will crash. If you delete/uncomment the TextBoxWatermarkExtender everything works fine.

    Any solution for this?

    Thanks,
    Dirk

  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    05-09-2006, 1:33 PM
    • Contributor
      4,346 point Contributor
    • sburke_msft
    • Member since 04-04-2006, 7:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam

    Visible = false causes ASP.NET to not render the control.  So you've got a behavior on your page looking for a client element that doesn't exist in the rendered HTML.

    Use:

    UpdatePanel2.Style.Add("display", "none"); // hide

    and

    UpdatePanel2.Style.Remove("display"); // show

    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    05-10-2006, 5:01 AM
    • Member
      72 point Member
    • dirkb
    • Member since 01-06-2006, 11:35 AM
    • Germany
    • Posts 15

    Thanks for your reply. It is working this way but I can't believe that the Atlas client side scrips are not validating this behavior and check for null refs caused by this.

    It is not very intuitive for an ASP.net developer...

  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    05-10-2006, 1:34 PM
    • Contributor
      4,346 point Contributor
    • sburke_msft
    • Member since 04-04-2006, 7:28 PM
    • Redmond, WA
    • Posts 770
    • AspNetTeam
    Well they kind of are - hence the error you got...
    Don't forget, this posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    07-07-2006, 5:19 PM
    • Member
      77 point Member
    • dfmartin
    • Member since 06-22-2002, 12:14 PM
    • Nashville, TN
    • Posts 17

    I'm getting this same error for pretty much the same reason.  However, I am using a multiview (also happens for a wizard).  I have a textbox within an UpdatePanel within a view.  That particular view is not shown when the page loads due to business requirements.  When any type of postback occurs the WebForm_OnSubmit() fires.  In this function the TWE has embedded Sys.Application.findObject('mycontrolnamehere')._onSubmit().  Since that control is on a hiden view (not rendered HTML) the find object returns null, thus the ._onSubmit() is invalid.  I believe the OP was refering to this when he said the controls ought to catch this.  _onSubmit should not be called if there is no object reference returned by the findObject method.

    Here is my code.  The textbox in question is in the second view.

     

     
    <atlas:ScriptManager ID="sm1" runat="server" EnablePartialRendering="true"></atlas:ScriptManager>
    	   
    	<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    <atlas:UpdatePanel ID="up1" Mode="Conditional" runat="server">
    	<ContentTemplate>
    		<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    		<asp:View ID="step1" runat="server">
    			BCU/PBU/Location<br />
    			<br />
    			<atlas:UpdatePanel ID="UpdatePanel2" runat="server">
    				<ContentTemplate>
    					1. Select BCU:<br />
    					<asp:DropDownList ID="ddBCU" runat="server" OnSelectedIndexChanged="ddBCU_SelectedIndexChanged" AutoPostBack="True">
    					</asp:DropDownList><br />
    					<br />
    					2. Select PBU:<br />
    					<asp:DropDownList ID="ddPBU" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddPBU_SelectedIndexChanged">
    					</asp:DropDownList>
    					<br />
    					<br />
    					3. Select Location:<br />
    					<asp:DropDownList ID="ddLocation" runat="server" Enabled="False">
    					</asp:DropDownList>
    					<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="ddLocation"
    						ErrorMessage="* Required" MaximumValue="99999" MinimumValue="1" Type="Integer"></asp:RangeValidator>
    				</ContentTemplate>
    			</atlas:UpdatePanel>
    			<br />
    			<br />
    		</asp:View>
    		<asp:View ID="step2" runat="server">View Two<cc2:textboxwatermarkextender id="TextBoxWatermarkExtender1" runat="server">
    		<cc2:TextBoxWatermarkProperties TargetControlID="TextBox1" WatermarkCssClass="myTextboxEmpty"
    			WatermarkText="Enter name" />
    			<cc2:TextBoxWatermarkProperties TargetControlID="TextBox2" WatermarkText="entersomething difference here" />
    	</cc2:textboxwatermarkextender>
    	<br />
    			<atlas:UpdatePanel ID="UpdatePanel3" runat="server">
    				<ContentTemplate>
    			<asp:TextBox ID="TextBox1" runat="server" CssClass="myTextbox"></asp:TextBox>
    					<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
    						ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    					<br />
    				</ContentTemplate>
    			</atlas:UpdatePanel>
    			  <br />
    			 </asp:View>
    		<asp:View ID="step3" runat="server">
    				view Three<br />
    				<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
    			  
    	</asp:View>
    		</asp:MultiView>
    	</ContentTemplate>
    	<Triggers>
    		<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
    		<atlas:ControlEventTrigger ControlID="btnNext" EventName="Click" />
    		<atlas:ControlEventTrigger ControlID="btnPrevious" EventName="Click" />
    	</Triggers>
    </atlas:UpdatePanel>
    	<atlas:UpdatePanel ID="UpdatePanel1" runat="server">
    		<ContentTemplate>
    			<asp:Button ID="btnPrevious" runat="server" OnClick="btnPrevious_Click" Text="Previous" /> 
    			<asp:Button ID="btnNext" runat="server" OnClick="btnNext_Click" Text="Next" />
    		</ContentTemplate>
    	</atlas:UpdatePanel>
    
     
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    07-10-2006, 4:22 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842

    The 60626 release of the Toolkit doesn't render controls whose TargetControlID is Visible=false. That should address the problem here, so please try with that release (or later).


    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    07-11-2006, 8:57 AM
    • Member
      77 point Member
    • dfmartin
    • Member since 06-22-2002, 12:14 PM
    • Nashville, TN
    • Posts 17

    It appears the problem is still there.  Here is the code that is getting rendered to the browser.  Keep in mind that the textbox referenced in on view #2 and this error is getting called when a dropdown on view #1 triggers a callback.  The entire view is inside of an update panel.  And the specific error is:  'Sys.Application.findObject(...)' is null or not an object.

    For now I am getting around it by changing the source code.  Line 40 of TextboxWatermarkExtender.cs (OnLoad override).

    // Rendered Code
    function WebForm_OnSubmit() { Sys.Application.findObject('_ctl00_ContentPlaceHolder1_TextBox1')._onSubmit();if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false; return true; }
      
    // Modified Code
    string
    script = string.Format(CultureInfo.InvariantCulture, "if ( Sys.Application.findObject('{0}') != null ) Sys.Application.findObject('{0}')._onSubmit();", textBoxWatermarkProperties.ID);

     Thanks for your input on this, and great job!

    -David Martin

  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    07-11-2006, 5:20 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842
    Now that I better understand the scenario, I think that your workaround seems like a reasonable thing to do. I've opened work item 886 to fix this. Thanks!

    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    07-22-2006, 8:11 PM
    • Star
      8,710 point Star
    • David Anson
    • Member since 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842

    I've just checked in the proposed fix for the next release of the Toolkit. Check-in notes:

    Modify TextBoxWatermark's RegisterOnSubmitStatement implementation to gracefully handle the case when the behavior can't be found. This can happen when paging through the MultiView control and switching from a view that didn't have a TextBoxWatermark. The Page object has a TextBoxWatermark, so its OnLoad method runs, but the content that's rendered to the client doesn't get the TextBoxWatermark behavior because the relevant control isn't present in that view. Simple fix is to detect the "missing behavior case" and ignore it per forum feedback/suggestion.


    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: TextBoxWatermarkExtender crashes UpdatePanel

    08-03-2006, 2:03 AM
    • Member
      195 point Member
    • jyoti22apr
    • Member since 07-20-2006, 4:06 AM
    • Posts 40

    i have to add   ContentTemplate in UpdatedPanel    programatically in runtime without use of clienside all do in CodeBehind .CS file.

Page 1 of 1 (10 items)