Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
        }
    }
share|improve this question
add comment

1 Answer 1

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;
 }
share|improve this answer
    
I have purged all comments. If you feel like chatting to each other we have a chat forum right here where you can discuss things further: chat.stackexchange.com/rooms/411/sharepoint –  Anders Rask May 7 '13 at 12:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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