I have a user control,
In user control I have a button, which when is clicked, shows a message box ,
message box has a textbox and another button,
when I click on another button, I need to get textbox value in code behind, but it's not happening at all, as button is doing partial postback and textbox just loses it's state.
I can't get textbox value in page_load method and save it to session state as textbox is populating dynamically
this is what i tried so far,
<asp:TextBox ID="textbox1" TextMode="MultiLine" runat="server" />
and
protected void Button1_Click(object sender, EventArgs e)
{
string button1text = TextBox1Text;
and
public partial class myUserControl : UserControl
{
public string TextBox1Text
{
get
{
return Page.Session["TextBox1Text"] as string;
}
set
{
Page.Session["TextBox1Text"] = TextBox1.Text;
}
}
No Gain but Only Pain.
It's been a while since I used UpdatePanels, but I believe that on partial postback they only send updated values for controls inside them. So move the TextBox inside the UpdatePanel, or perhaps use Javascript to populate a hidden control inside the UpdatePanel with the contexts of the TextBox whenever it is updated.
in ASP page
<input type="hidden" id="hidtext" runat="server" value="">
in C#
hidtext.Value=textbox1.text;
or VB
hidtext.Value=textbox1.text
after post back
textbox1.text=hidtext.value;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With