kumar
kumar

Reputation: 1127

how to assign a value to textbox which is outside of the updatePanel

i am having a Page.in that page button inside a UpdatePanel.when a user click on the button. i need to assign a value to textbox which is outside of the updatepanel.

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

Upvotes: 2

Views: 3628

Answers (3)

Atzoya
Atzoya

Reputation: 1387

You can also place the TextBox in a Update panel, leave the button out of the update panel and set a trigger that will cause the button to do a 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>

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

Or if you don't want to add the text box in a Update Panel you can register a startup script 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);

Upvotes: 2

Gabriel Guimar&#227;es
Gabriel Guimar&#227;es

Reputation: 2744

Place the TextBox in a updatepanel with a trigger to the button here's a example:

<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 Button Click, you can change the value of txtBox1 and call upd2.Update()

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062600

IIRC You would need to call .Update() on the additional controls (perhaps placing them in a second UpdatePanel and calling .Update() on that). See MSDN for an example.

Upvotes: 0

Related Questions