0

i have a user control, which has update panel and a button in it, when i click on button a message box appears, in messagebox i have one text box and another button,

when i click on another button, update panel triggers code behind method, now in my user control i need 2 get textbox text but no working

<asp:TextBox ID="textbox1" TextMode="MultiLine" runat="server" />

in usercontrol i am trying to ;

textbox1.text 

but it is always empty

now in button click it is this'

protected void Button1_Click(object sender, EventArgs e)
        {
string button1text = TextBox1Text;

also added this,

public partial class myUserControl : UserControl
{
    public string TextBox1Text
    {
        get 
        {
            return Page.Session["TextBox1Text"] as string;  
        }
        set
        {
            Page.Session["TextBox1Text"] = TextBox1.Text;
        }
    }

1 Answer 1

0

for usercontrol only!

public partial class myUserControl : UserControl
{
    public string TextBox1Text
    {
        get 
        {
            return Page.Session["TextBox1Text"] as string;  
        }
        set
        {
            Page.Session["TextBox1Text"] = TextBox1.Text;
        }
    }
}

the above is fine! you now need to put value into it when you click the button!

protected void Button1_Click(object sender, EventArgs e)
{
     //save value to session state
     TextBox1Text = textbox1.Text;
}

now within your onload function you can reload the value!

 if(!Page.IsPostback)
 if (TextBox1Text != null)
 {
    //get value from the session state!
    textbox1.Text = TextBox1Text;
 }
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.