How to assign a value to a textbox that is outside the updatePanel

I have the page.in button of this page inside the UpdatePanel. When the user clicks on the button. I need to assign a value to a textbox that is outside of the update bar.

how to achieve this? any suggestion that it will be there?

+2


source to share


3 answers


You can also put the TextBox on the Update panel, leave the button on the Update panel, and set a trigger that will cause the button to do an Async postback like this:

<asp:Button ID="btnSubmit" runat="server />
<asp:UpdatePanel ID="upTextBox" runat="server">
     <ContentTemplate>
           <asp:TextBox ID="tbTitle" runat="server" />
     </ContentTemplate>
     <Triggers>
           <asp:AsyncPostBackTrigger ControlID="btnSubmit" />
     </Triggers>
</asp:UpdatePanel>

      

Then add a button event that will change the text of the text box.



Or, if you don't want to add a textbox in the refresh panel, you can register a script run to set the text of the textbox something like this:

ScriptManager.RegisterStartupScript(this, GetType(), "setTextBoxText", "<script type='text/javascript'>$('#"+tbTitle.ClientId+"').val('submit button has been clicked');</script>", false);

      

+2


source


Place the TextBox in the update bar using the trigger on the button here:

<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<asp:Button ID="Btn1" runat="server />
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="upd2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtBox1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Btn1" />
</Triggers>
</asp:UpdatePanel>

      



And on the Click button, you can change the value of txtBox1 and call upd2.Update ()

+1


source


IIRC you will need to name .Update()

on additional controls (perhaps putting them in a second UpdatePanel

and naming .Update()

) on this one). See MSDN for an example.

0


source







All Articles