views:

110

answers:

2

Dear all,

I am going to show some text in a TextBox, which is located outside of an updatepanel, after checking a CheckBox but I cannot make it work. please help me out ?

Here is my code:

<asp:UpdatePanel runat="server" ID="uplMaster">
    <ContentTemplate>
        <asp:CheckBox ID="cbShowText" runat="server" Text="Show Some Text" AutoPostBack="true"
            OnCheckedChanged="cbShowText_CheckedChanged" />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="txtBox" Text="Empty" runat="server" />

Code Behind:

    protected void cbShowText_CheckedChanged(object sender, EventArgs e)
    {
        txtBox.Text = "Some Text";
    }

Thanks in advance :D

P.S. As you might have guessed, I have resembled my problem and that is why I don't want to put the TextBox in the UpdatePanel

+1  A: 

The textbox has to be in update panel also.

*Edit:

I am sorry I didn't read your question properly. Perhaps write a javascript function, and call the function from codebehind?

Lee Sy En
Thanks for your comments. Can you please tell me any server-side solution?
Matin Habibi
A: 

I put the TextBox in another UpdatePanel and then called the Update method:

Here is my new code:

    <asp:UpdatePanel runat="server" ID="uplMaster" UpdateMode="Always">
    <ContentTemplate>
        <asp:CheckBox ID="cbShowText" runat="server" Text="Show Some Text" AutoPostBack="true"
            OnCheckedChanged="cbShowText_CheckedChanged" />
    </ContentTemplate>
   </asp:UpdatePanel>
   <asp:UpdatePanel runat="server" ID="uplDetail" UpdateMode="Conditional">
       <ContentTemplate>
           <asp:TextBox ID="txtBox" Text="Empty" runat="server" />
       </ContentTemplate>
   </asp:UpdatePanel>

Code Behind:

        protected void cbShowText_CheckedChanged(object sender, EventArgs e)
        {
           txtBox.Text = "Some Text";
           uplDetail.Update();
        }

Hope this helps

Matin Habibi