Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

get text of all the textbox inside episerver pagelist

Vote:
 

Hi I have a episerver pagelist  showing the name of page and textbox field which is editable. Then I have a button in my page which is not inside the pagelist. onclick of this button i want all the values of the textbox. I am trying

private void Button_Click(object sender, System.EventArgs e)
        {
                foreach (PageList item in productList)
                {
                    Response.Write(((TextBox)item.Controls[1]).Text);
                   
                
                }

where productList is the id of the pageList. But dosnt work.Please help

#47099
Jan 14, 2011 7:47
Vote:
 

There are several ways of doing this but you can try

private void Button_Click(object sender, System.EventArgs e)
{
 var boxes=new List<TextBox>();
 FindControls(productList,boxes,"id2box");
 foreach (TextBox box in boxes) 
 {
  Response.Write(box.Text); 
 }
}       

void FindControls(System.Web.UI.Control start, List<TextBox> result,string id)
{
    foreach (System.Web.UI.Control item in start.Controls)
    {
        if (item is TextBox && (item as TextBox).ID==id)
            result.Add(item as TextBox);
        FindControls(item, result,id);
    }
}

#47102
Jan 14, 2011 9:30
Vote:
 

Hi,

thanks for the reply.But my pagelist is like

<EPiServer:PageList  runat="server" ID="productList" >                
           
                        <ItemTemplate>
                           <tbody>
                            <tr>
                                <td><img src='<%# GetImageURL(((EPiServer.Core.PageData)Container.DataItem).PropertyValue<string>("ProductID")) %>' alt=""></td>
                                <td width="20"><h4><a href="<%#Eval("LinkURL") %>"><%# Container.CurrentPage.PageName %></a></h4>
                                   <%# Container.CurrentPage.Property["MarketingName"].Value %>
                                </td>
                               
                                <td>Määrä<asp:TextBox ID="txtFirstName" runat="server" ></asp:TextBox>
                                <td><asp:LinkButton  runat="server" class="remove" Text="Poista" OnCommand="removeProduct" CommandArgument="<%# Container.CurrentPage.PageLink %>"></asp:LinkButton>
                               </td>
                           </tr>
                           </tbody>
                        </ItemTemplate>
                    
                     </EPiServer:PageList

along with the value of text I also know it is bounded to whichPagelink "Container.CurrentPage.PageLink"?

#47103
Jan 14, 2011 10:04
Vote:
 

You have several options here. The quick fix is to add

<asp:TextBox ID="txtFirstName" runat="server" ToolTip="<%# Container.CurrentPage.PageLink %>" />

other methods could be to have an Literal that is visible=false with the pagelink. Then find all Literals with the same method

or to change the id on the textbox to have the pageID

#47104
Jan 14, 2011 10:58
Vote:
 

but you could also add it to your link button the same way you add the page link

<asp:LinkButton  runat="server" class="remove" Text="Poista" OnCommand="removeProduct" CommandArgument="<%# Container.CurrentPage.PageLink %>_<%#Container.FindControl("txtFirstName").UniqueID %>"></asp:LinkButton>

 

#47106
Edited, Jan 14, 2011 11:18
Vote:
 

hey thanks for the reply

when I tried to add the pageID as a Id in the textbox. The textbox started dissappear from my page. I cant use tooltip because its showing up.Please suggest is there any other way to do so?

#47107
Edited, Jan 14, 2011 11:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.