Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a control outside of an updatepanel?

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

like image 365
Matin Habibi Avatar asked May 19 '10 10:05

Matin Habibi


People also ask

How do you refresh the UpdatePanel?

Now to refresh the UpdatePanel using JavaScript, you just need to access the Button and call its Click function. This way the Button's OnClick event handler on server side is invoked and the Label displays the current time. Another way is to make use of the __doPostBack JavaScript method of ASP.Net.

Which of the following is the property of UpdatePanel control?

If the UpdateMode property is set to Always, the UpdatePanel control's content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.

What happens when a button placed in the UpdatePanel control is clicked?

The UpdatePanel control contains a Button control that refreshes the content inside the panel when you click it.

How do I stop UpdatePanel from causing the whole page postback?

To fix the problem, you just need to set ClientIDMode="AutoID" on the control(s) which should trigger the UpdatePanel post back.


1 Answers

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

like image 185
Matin Habibi Avatar answered Oct 06 '22 20:10

Matin Habibi