How to assign a value to a textbox that is outside the updatePanel
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 to share
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 to share