coctile
coctile

Reputation: 83

ASP Repeater item command doesn't work

i'm working on asp repeater control which have one or more link button, the problem is the item command never fired when i click the link button !

i spent the last 2 days searching about solution but i got nothing !

 <asp:Repeater ID="rptTweets" runat="server" 
               onitemcommand="rptTweets_ItemCommand">
     <HeaderTemplate>
         <ul>
     </HeaderTemplate>
     <ItemTemplate>
         <li>
             <div class="imgb">
                 <img src="<%# Eval("userImg") %>" width="35" 
                      height="35" alt="Comment" />
             </div>
             <asp:TextBox ID="txtTweet" runat="server" 
                          TextMode="MultiLine" Rows="5" Columns="5" 
                          EnableViewState="true" Text='<%# Eval("tweet")%>' >
             </asp:TextBox>
             <div class="edit">
                 <asp:LinkButton ID="btnView" runat="server" 
                                 CommandName="View" 
                                 CommandArgument='<%# Eval("tweet")%>' 
                                 CssClass="comment-edit">View</asp:LinkButton>
             </div>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

and here is the binding :

if (!IsPostBack)
{
    List<clsTweet> tw = getTweets();            

    rptTweets.DataSource = tw;
    rptTweets.DataBind();
}

and this my item command function:

protected void rptTweets_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    lblMsg.Text = "Working................................??";
}

Upvotes: 0

Views: 6325

Answers (3)

Moharrer
Moharrer

Reputation: 153

You must remove

if (!IsPostBack)

Upvotes: 0

coctile
coctile

Reputation: 83

this is the page renderd:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-latest.js"></script>
<script src="js/script.js" type="text/javascript"></script>
</head>

<body>
<form method="post" action="Drafts.aspx" id="Form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden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9iqINmF2K7YqtmE2YHYqSkuINmI2YfZiCDYo9mI2YQg2YbYp9iv2Y0g2YrYrdi12YQg2LnZhNmJINio2LfZiNmE2Kkg2KfZhNiv2YjYsdmKINin2YTYs9i52YjYr9mKINin2YTZhdmF2KrYp9iyLiDZgdmKIDEwINiz2KjYqtmF2KjYsSAyMDA5INij2LnZhNmGINmF2YjZgti5INin2YTYp9iq2K3Yp9ivINin2YTYr9mI2YTZiiDZhNmE2KXYrdi12KfYoSDZiNin2YTYqtin2LHZitiuIElGRkhTINit2LXZiNmEINmG2KfYr9mKINin2YTZh9mE2KfZhCDYp9mE2LPYudmI2K/ZiiDYudmE2Ykg2YTZgtioINmG2KfYr9mKINin2YTZgtix2YYg2YHZiiDZgtin2LHYqSDYotiz2YrYpyDZiNiw2YTZgyDYrtmE2KfZhCDZgdiq2LHYqSAoMTkwMS0yMDAwKWRkZBYW/O6+a+pPOSR0BG0yXmCFSqoYFrXa5HjYvvuLlOsq" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['Form1'];
if (!theForm) {
    theForm = document.Form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<div class="aspNetHidden">

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBQLPk4yNDgLTpKLUAwLTm+btDAKkiLKlCAK42v7pCPZE7CTv+APwWJhRfpfg6RxZx1JkCol595WLmQ5CgQ5q" />
</div>
<!-- start wrap -->
<div class="wrap">
    <!-- start header -->
    <div class="header">
        <!-- start box -->
        <div class="box">
            <!-- start logo -->
            <div class="logo">
                <a href="Default.aspx" title="Connctd Tweets"><img src="images/logo.png" width="202" height="55" alt="Connctd Tweets" /></a>
            </div>
            <!-- end logo -->
        </div>
        <!-- end box -->
    </div>
    <!-- end header -->
    <!-- start box -->
    <div class="box">
        <!-- start menu bar -->
        <div class="menu-bar">
            <!-- start menu-in -->
            <div class="menu-in">
                <!-- start navigation -->
                <div class="navigation">
                    <ul>                                 
                        <li><a href="Default.aspx" title="Home">Home</a></li>
                        <li><a href="About.aspx" title="About us">About us</a></li>
                        <li><a href="Contactus.aspx" title="Contuct us">Contuct us</a></li>
                    </ul>
                </div>
                <!-- end navigation -->
                <!-- start social -->
                <div class="social">
                    <ul>
                        <li class="facebook"><a href="#" title="Facebook">Facebook</a></li>
                        <li class="twitter"><a href="#" title="Twitter">Twitter</a></li>
                        <li class="linkedin"><a href="#" title="Linkedin">Linkedin</a></li>
                        <li class="google"><a href="#" title="Google">Google</a></li>
                    </ul>
                </div>
                <!-- end social -->
            </div>
            <!-- end menu-in -->
        </div>
        <!-- end menu bar -->
        <!-- start container -->
        <div class="container">
            <!-- start leftcol -->
            <div class="leftcol">
                <!-- start profile -->
                <div class="profile">
                    <div class="imgb"><img src="http://a0.twimg.com/profile_images/1860897105/DB0740DC-D194-4725-979A-D0BD00470116_normal" id="userImg" width="58" height="57" alt="Profile" /></div>
                    <p><span> <span id="lblFullName">عبدالرحمن المهوس</span> </span> <br />  
                        <span id="lblDescription" style="font-size:Small;">Developer, Geek, Founder Of www.ConnctdTwets.com</span> </p>
                </div>
                <!-- end profile -->
                <!-- start subnav -->
                <div class="subnav">
                    <ul>
                        <li class="logout"><a href="#" title="Logout"><span>Logout</span></a></li>
                        <li class="history"><a href="#" title="History"><span>History</span></a></li>
                        <li class="draft active"><a href="#" title="Draft"><span>Draft</span></a></li>
                        <li><input type="text" name="Search" value="Search ...." class="input" onfocus="if(this.value == 'Search ....') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Search ....'; }" /><input name="button" type="submit" value="" class="button" /></li>
                    </ul>
                </div>
                <!-- end subnav -->
            </div>
            <!-- end leftcol -->
            <!-- start rightcol -->
            <div class="rightcol">
                <!-- start tab -->
                <div class="tab">
                    <!-- start tab nav -->
                    <div class="tab-nav">
                        <ul>
                            <li><a href="#" title="Writing Tweet">Writing Tweet</a></li>
                            <li><a href="#" title="Writing Tweet" class="active">View Tweet</a></li>
                        </ul>
                    </div>
                    <!-- end tab nav -->
                    <!-- start gray box -->
                    <div class="gray-box">
                        <!-- start comment -->

                        <div id="divTweets" class="comment">

                            <ul>

                             <li>
                                    <div class="imgb"><img src="http://a0.twimg.com/profile_images/1860897105/DB0740DC-D194-4725-979A-D0BD00470116_normal" width="35" height="35" alt="Comment" /></div>
                                     <textarea name="rptTweets$ctl01$txtTweet" rows="5" cols="5" id="rptTweets_txtTweet_0">
???? ?????? ??????? ?? ???? ????? ?????? ????? ????? ?????? ?? ???? ??? ??????? ??????? 54 ????? ??? ????? ??? ????? ????????. ????? ??? ???? ???? ?????? ???? ??????? ??????? ?????? ?????? ??????? ??????? ?????? ??? ?????? ??? ???? ????? ??? ??? ??? ????? ????? ??? ?????? ???? ??????? ??????? ???? ???? ?????? (???? ?????? ???? ?? ???) ????? ????. ????? ???? ?????? ??????? ???? ??????? ???????? ??????? ???????? ???????? ????? (13 ????? ?????? ?????? ???????)? ????? ??????? ???????? ??????? ??????? ???????? (??? ????? ?? ???? ??????? ??????). ??? ??? ???? ???? ??? ????? ?????? ??????? ???????. ?? 10 ?????? 2009 ???? ???? ??????? ?????? ??????? ???????? IFFHS ???? ???? ?????? ??????? ??? ??? ???? ????? ?? ???? ???? ???? ???? ???? (1901-2000)</textarea>
                                    <div class="edit"><a id="rptTweets_btnView_0" class="comment-edit" href="javascript:__doPostBack(&#39;rptTweets$ctl01$btnView&#39;,&#39;&#39;)">View</a></div>
                                </li>

                             <li>
                                    <div class="imgb"><img src="http://a0.twimg.com/profile_images/1860897105/DB0740DC-D194-4725-979A-D0BD00470116_normal" width="35" height="35" alt="Comment" /></div>
                                     <textarea name="rptTweets$ctl02$txtTweet" rows="5" cols="5" id="rptTweets_txtTweet_1">
نادي الهلال السعودي هو نادي سعودي آسيوي، مقرّه مدينة الرياض إذ تبلغ عدد بطولاته الرسمية 54 بطولة على مستوى كرة القدم السعودية. إضافة إلى ذلك، يعدّ الهلال أكثر الأندية تحقيقاً لبطولة الدوري السعودي الممتاز بثلاثة عشر بطولة، إلى جانب تزعمه على كأس ولي العهد بإثنى عشر بطولة، وكأس الاتحاد السعودي الذي سُمي لاحقاً (بكأس الأمير فيصل بن فهد) بسبعة مرات. ويُعد نادي الهلال السعودي أكثر الأندية السعودية تحقيقاً للبطولات الخارجية بواقع (13 بطولة خليجية وعربية وآسيوية)، وأكثر الأندية الآسيوية تحقيقاً للألقاب الآسيوية (ستة ألقاب في ثلاث مسابقات مختلفة). وهو أول نادٍ يحصل على بطولة الدوري السعودي الممتاز. في 10 سبتمبر 2009 أعلن موقع الاتحاد الدولي للإحصاء والتاريخ IFFHS حصول نادي الهلال السعودي على لقب نادي القرن في قارة آسيا وذلك خلال فترة (1901-2000)</textarea>
                                    <div class="edit"><a id="rptTweets_btnView_1" class="comment-edit" href="javascript:__doPostBack(&#39;rptTweets$ctl02$btnView&#39;,&#39;&#39;)">View</a></div>
                                </li>

                            </ul>






                        </div>




                        <!-- end comment -->

                    </div>
                    <!-- end gray-box -->
                </div>
                <!-- end tab -->
            </div>
            <!-- end rightcol -->
            <div class="clear"></div>
        </div>
        <!-- end container -->
    </div>
    <!-- end box -->
</div>
<!-- end wrap -->
 </form>
</body>
</html>

Upvotes: 0

Praveen Nambiar
Praveen Nambiar

Reputation: 4892

You are missing this - e.CommandName :

protected void rptTweets_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if(e.CommandName == "View") // add this
    {
        lblMsg.Text = "Working................................??";
    }
}

Also check to see if the ViewState is not disabled for your page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" EnableViewState="false" %>

If its set to false, set it to true or just remove it as by default its set to true

Upvotes: 0

Related Questions