Need a little help with some Web Part

Last post 06-24-2009 4:55 AM by ssherif. 2 replies.

Sort Posts:

  • Need a little help with some Web Part

    06-24-2009, 2:48 AM
    • Member
      point Member
    • ssherif
    • Member since 06-24-2009, 2:25 AM
    • Posts 2

    Hi all

    I'm designing a page around web parts (which I'm completely new to) and I've got a question that feels kind of silly to ask.

    The way my project is set up is that I named a .ascx file addPart.ascx and this file contains a button and a textbox (named txtAdd). Then, on another form (mainForm.aspx), I added a webpartzone and added my addPart.ascx to the zone. What I want to do is modify the txtAdd.Text property when the page loads, but I can't access it from mainForm.vb as the text box is declared in the addPart.ascx file.

    Pushing the button isn't a problem as I can  just double click the button on the addPart.ascx file and write the needed code there.

     

    If anyone could give me a hand I'd really appreciate it, thanks.

    Filed under:
  • Re: Need a little help with some Web Part

    06-24-2009, 3:21 AM
    Answer
    • All-Star
      89,434 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,526
    • TrustedFriends-MVPs

    ssherif:

    I'm designing a page around web parts (which I'm completely new to) and I've got a question that feels kind of silly to ask.

    The way my project is set up is that I named a .ascx file addPart.ascx and this file contains a button and a textbox (named txtAdd). Then, on another form (mainForm.aspx), I added a webpartzone and added my addPart.ascx to the zone. What I want to do is modify the txtAdd.Text property when the page loads, but I can't access it from mainForm.vb as the text box is declared in the addPart.ascx file.

     

    Here's an example:

    VB.NET

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If WebPartManager1.WebParts.Count > 0 Then
            Dim wp As WebPart = DirectCast(WebPartManager1.WebParts("WebUserControl1"), WebPart)
            Dim tb As TextBox = DirectCast(wp.Controls(0).FindControl("TextBox1"), TextBox)
            If tb IsNot Nothing Then
                tb.Text = "Hello ASPNET!"
            End If
        End If
    End Sub


     

    C#

     protected void Page_Load(object sender, EventArgs e)
        {
            if (WebPartManager1.WebParts.Count > 0)
            {
                WebPart wp = (WebPart)WebPartManager1.WebParts["WebUserControl1"];
                TextBox tb = (TextBox)wp.Controls[0].FindControl("TextBox1");
                if (tb != null)
                {
                    tb.Text = "Hello ASPNET!";
                }
            } 
        }


     

    Regards, Vinz
    SDE |Microsoft MVP - ASP/ASP.NET


    ~Currently looking for an overseas job opportunity~
  • Re: Need a little help with some Web Part

    06-24-2009, 4:55 AM
    • Member
      point Member
    • ssherif
    • Member since 06-24-2009, 2:25 AM
    • Posts 2

     Perfect, thanks very much!

Page 1 of 1 (3 items)