开发者

FindControl() Keeps Returning Null!

I realise there are many posts on the web about th开发者_JAVA技巧is already but I cant seem to find any for my particular problem!

I have a dynamic table that is populated using a repeater.

the code is:

<asp:Repeater ID="rptPending" runat="server">
    <HeaderTemplate>
        <table id="tblPending" cellpadding="0" cellspacing="0" border="0" class="display">
            <thead>
                <tr>
                    <th>Company Name</th>
                    <th>Telephone</th>
                    <th>Fax Number</th>
                </tr>
            </thead>
            <tbody>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td runat="server">
                <asp:TextBox ID="a" runat="server" TextMode="MultiLine" Rows="1" 
                onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));" 
                Text='<%# Eval("_companyName")%>'></asp:TextBox>
            </td>                          
            <td runat="server">                           
                <asp:TextBox ID="b" runat="server" TextMode="MultiLine" Rows="1" 
                onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));" 
                Text='<%# Eval("_telephone")%>'></asp:TextBox>
            </td>                          
            <td runat="server">                           
                <asp:TextBox ID="c" runat="server" TextMode="MultiLine" Rows="1" 
                onChange="__doPostBack($(this).attr('name'),$(this).parent().attr('id'));" 
                Text='<%# Eval("_faxNo")%>'></asp:TextBox>
            </td>                
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </tbody> </table>
    </FooterTemplate>
</asp:Repeater>

Once this table has been populated with data from a datasource, a jquery script iterates through every table cell and edits the id's accordingly. cell_0_0, cell_0_1, cell_0_2 etc.

Now When the text on these text areas change, a postback is initiated, with the __EVENTTARGET being the textarea ID, and the __EVENTARGUMENT being the table cell (parent) ID.

These get sent to the server-side no problem. The issue I am having is GETTING THE TEXT inside the text area...

I have tried adding controls using FindControl("cell_0_0"); Which returns null. Then i found out the FindControl() function IS NOT recursive, so i copied a recursive function off the net... and it Still Fails!

Basically ALL i need to do is GET the value (either innerText or InnerHTML). Ive tried using Control, HtmlControl, HtmlTableRow, and HtmlTextArea.

I just cant seem to get the value. Ive tried recursing throught i a noted earlier, but the controls arent even registered. Im confused.

PLEASE HELP!

Thanks

Alex


Well this is a usually issue, because of the timing of the creations of the controls, and when you create control inside a repeater the timing is even more complex because repeater must first full bind, and then search for the controls.

In my programs to avoid all that I just get the posted value from the Form and I actually not first search to find the control. So just get your posted values from the Request.Form and move on.

Request.Form

All the post data lives on Request.Form, so you can simple get the one you need, or find the one you need. Just a note, to get a value using the Form use the UniqueID, and not the ClientID. Even better get the value from your custom name ids.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜