2012-03-13 3 views
0

TextBox 및 LinkButton이 포함 된 Repeater가 있습니다. 하는 LinkButton을 클릭하면, 나는 EVENT Repeater1_ItemDataBound (개체를 보낸 사람, RepeaterItemEventArgs 전자) 나는 전자 = 텍사스 텍스트 상자를 사용하여 텍스트 상자의 값을 얻을 수 있어요 사용 ...이벤트 처리기 TextBox 컨트롤이있는 OnItemCommand

TextBox.Text를 잡고 물건을 할 필요가 내가 다시 아무것도 못하고 오전 EVENT Repeater1_ItemCommand (개체를 보낸 사람, RepeaterCommandEventArgs 전자)를 사용하여 텍스트 상자

그러나

로 .Item.FindControl ("txCode"). TextBox가 비어 있습니다.

어떻게 'OnItemCommand'를 사용하여 TextBox에서 텍스트/콘텐츠를 가져올 수 있습니까? 내가

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    TextBox tx = e.Item.FindControl("txCode") as TextBox; 
    string myText = tx.Text; '<--- working 
} 

아래의 텍스트 상자의 값을 얻을 수 있어요

<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound" OnItemCommand="Repeater1_ItemCommand"> 
    <ItemTemplate> 
     <li>      
     <asp:TextBox ID="txCode" runat="server"></asp:TextBox> 
     <asp:LinkButton CommandName="verifyCode" ID="lbCode" runat="server">Submit<asp:LinkButton> 
     </li> 
    </ItemTemplate> 
</asp:Repeater> 

내가하는 Repeater를 결합하지 마십시오

protected void Repeater1_ItemCommand(object sender, RepeaterCommandEventArgs e) 
{ 
    if (e.CommandName == "verifyCode") 
    { 
     TextBox tx = e.Item.FindControl("txCode") as TextBox; 
     string myText = tx.Text; '<--- NOT working 
} 
+2

는이 이벤트가 발생합니다 있는지 확인하기 위해 디버깅이 있나요? 아마 당신은 Page_Load에서'! IsPostBack'을 체크하지 않았을 것입니다. 포스트 백에없는 repeater를 DataSource에 바인딩하십시오. –

+0

if (! IsPostBack) - Damm <- worked! 감사합니다 @ 팀 Schmelter –

답변

2

아래의 텍스트 상자의 값을 얻을 수 없습니다입니다 모든 포스트 백에 대해 DataSource입니다. 그렇지 않으면 ViewState를 올바르게 다시로드 할 수 없으므로 이와 같은 문제가 발생합니다. ViewState을 사용하는 경우

그래서 항상를 Page_Load에서 IsPostBack property을 확인 (EnableViewState=true) :

if(!IsPostBack)BindRepeaterToDataSource();