This is a migrated thread and some comments may be shown as answers.

Updating a panel from a button outside a panel , cause controls inside panel to update the panel

3 Answers 68 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Chris H
Top achievements
Rank 1
Chris H asked on 07 May 2009, 11:07 AM

Hello,

I've created a panel ("Panel1") with a textbox ("TextBox1") inside it.
Outside "Panel1"  I have a button ("Button1")

I also have a "Panel2" with a label ("Label2") inside it

When the text in TextBox1 changes, I want to update "Label2"/ "Panel2", WITHOUTupdating "Panel1"
When "Button1" is clicked, I want to update "Panel1"

This does not seem to work.
When I update "Textbox1", "Panel1" is updated as well. I don't want that. I just want to update "Panel2"

If I remove ajax on "Button1", it works as expected.
"Panel2" is updated, and "Panel1" does not update.

Is this a bug ?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="test2" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
 
 
<!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 id="Head1" runat="server">  
    <title></title>  
</head> 
<body> 
 
<script runat="server">  
        public void Textbox1_TextChanged(object sender, EventArgs e)  
        {  
 
            //this.label_res.Text = this.Textbox_test.Text + " " + DateTime.Now;  
            //this.label1.Text = this.Textbox_test.Text + " " + DateTime.Now;  
 
            this.LabelResult2.Text = this.Textbox1.Text + " " + DateTime.Now;  
 
        }  
 
        public void Button1_Click(object sender, EventArgs e)  
        {  
 
        }      
</script> 
 
      
 
      
      
    <form id="form1" runat="server">  
 
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">  
    </asp:ScriptManager> 
 
        <telerik:RadAjaxManager runat="server" ID="Radajaxmanager2" UpdatePanelsRenderMode="Inline" > 
            <AjaxSettings> 
              
                <telerik:AjaxSetting AjaxControlID="Textbox1" > 
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl   ControlID="Panel2"/>  
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
 
                <telerik:AjaxSetting  AjaxControlID="Button1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl  ControlID="Panel1"/>  
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
              
            </AjaxSettings> 
         
        </telerik:RadAjaxManager> 
      
      
      
      
      
    Outside panel:  
    <asp:Label runat="server" ID="label_clockOutsidePanel"></asp:Label><br /><br /> 
      
 
          
        <!-- this panel should only update when BUTTON1 is clicked --> 
        <asp:Panel runat="server" ID="Panel1" BorderStyle="Solid">  
        
            Inside panel:  
            <asp:Label runat="server" ID="label_clockInsidePanel"></asp:Label><br /><br /> 
              
            <asp:TextBox  runat="server" ID="Textbox1" AutoPostBack="true"  ontextchanged="Textbox1_TextChanged">  
            </asp:TextBox> 
              
            <br />             
            <br />              
        </asp:Panel> 
          
          
        <asp:Button runat="server" ID="Button1" Text="Update the panel"    onclick="Button1_Click"   />      
 
        <asp:DropDownList  runat="server" id="Dropdownlist1" AutoPostBack="true">  
        <asp:ListItem Text="aaaa" Value="aaaa"></asp:ListItem> 
        <asp:ListItem Text="bbbb" Value="bbbb"></asp:ListItem> 
        <asp:ListItem Text="cccc" Value="cccc"></asp:ListItem> 
        </asp:DropDownList> 
 
 
        <br /><br /><br /> 
        <br /><br /><br /> 
 
        <!-- This panel should only update when TEXTBOX1 Changes --> 
        <asp:Panel runat="server" ID="Panel2">              
            <asp:Label runat="server" ID="LabelResult2"></asp:Label>              
        </asp:Panel> 
 
 
 
 
<br /><br /> 
      
 
 
 
 
 
      
      
    </form> 
</body> 
</html> 

3 Answers, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 08 May 2009, 09:53 AM
Hi,

I guess there is any code behind - could you post this also please!

Regards

Manfred
0
Chris H
Top achievements
Rank 1
answered on 08 May 2009, 11:54 AM
Hello,

The code-behind has been placed in the markup as inline script.
(See the  <script runat="server"> .. after BODY element

All you have to do is to create a blank aspx, and past all of the code into the markup portion

0
ManniAT
Top achievements
Rank 2
answered on 08 May 2009, 01:08 PM
Hi Chris,

sorry for that.
But since your code did not alter panel1 I could not see it.
So I changed the code a bit to:
        public void Textbox1_TextChanged(object sender, EventArgs e)     
        {     
    
            //thisthis.label_res.Text = this.Textbox_test.Text + " " + DateTime.Now;     
            //thisthis.label1.Text = this.Textbox_test.Text + " " + DateTime.Now;     
    
            thisthis.LabelResult2.Text = this.Textbox1.Text + " " + DateTime.Now;  
            this.label_clockInsidePanel.Text = "test from text";  
        }     
    
        public void Button1_Click(object sender, EventArgs e)     
        {  
            this.LabelResult2.Text = "Test";  
            this.label_clockInsidePanel.Text = "test from button";   
              
        }         
 
And I can confirm the following:
Pressing the button set's "test from button" ==> OK
Pressing the button does NOT set "Test" as text for LabelResult2.text ==> OK
Leaving the textbox (focus lost) fires TextChanged ==> OK.
The handler sets labelResult2.Text ==> OK
The handler sets label_clockInsidePanel.Text ==> CONFUSION :)

But sorry - I have no idea why this happens

Manfred
Tags
Ajax
Asked by
Chris H
Top achievements
Rank 1
Answers by
ManniAT
Top achievements
Rank 2
Chris H
Top achievements
Rank 1
Share this question
or