开发者

How can call a jQuery function when it is inside the formview (asp.net control)?

开发者 https://www.devze.com 2022-12-27 17:43 出处:网络
I have a Span in side the Form view. I wanted to call a jQuery function when the from load, how can I do this?

I have a Span in side the Form view. I wanted to call a jQuery function when the from load, how can I do this?

Here is my code:

 <asp:FormView ID="FormView1" runat="server" OnItemCommand="FormView1_ItemCommand">
            <ItemTemplate>
                <asp:HiddenField ID="hidProductID" Value='<%#Eval("ProductID") %>' runat="server" />
                <asp:HiddenField ID="hidCustomerID" Value='<%#Eval("CustomerID") %>' runat="server" />
                <a href='<%=WinToSave.SettingsConstants.SiteURL%>WintoSave/AuctionProduct.aspx?id=<%#Eval("ProductID") %>'>
                    <%#Eval("ProductName")%>
                </a>
                <br />
                <img src='<%#Eval("ImagePath")%>' alt="Image No available" />
                <br />
                <asp:Label ID="lblTime" runat="server" Text='<%#Convert.ToDateTime(Eval("ModifiedOn")).ToString("hh:mm:ss") %>'></asp:Label>

                 <span id='Countdown_<%#Eval("ProductID") %>' onload="GetTimeOnLoad('<%#Eval("ModifiedOn")%>','Countdown_<%#Eval("ProductID") %>');"></span>
                <br />
                <asp:Label ID="lblFinalPrice" runat="server" Text='<%#Convert.ToDouble(Eval("FinalPrice")).ToString("#.00")%>'></asp:Label>
                <br />
                <asp:Label ID="lblFullName" runat="server" Text='<%#Eval("FullName") %>'></asp:Label>
                <br />
                <asp:Button ID="btnAddbid" Text="Bid" CommandName="AddBid" CommandArgument='<%#Eval("ID")%>'
                    runat="server" />
            </ItemTemplate>
        </asp:FormView>
开发者_StackOverflow中文版

and following is my jquery code

   function GetTimeOnLoad(shortly,DivID)
   {
    var dt = new Date(shortly);
    alert(dt);
    alert(shortly);
    alert(DivID);
    var ProductDivID = "#" +DivID;
    alert(ProductDivID);
     $(ProductDivID).countdown({
            until: dt, onExpiry: liftOff, onTick: watchCountdown,
            format: 'HMS', layout: '{hnn}{sep}{mnn}{sep}{snn}'
        });
   }
   function liftOff(){};
   function watchCountdown(){};

In above code I Used ' onload="GetTimeOnLoad('<%#Eval("ModifiedOn")%>','Countdown_<%#Eval("ProductID") %>');"> but is not working


I would perhaps try somthing like this instead of the onload attribute.

Change your span line to:

<span id='Countdown_<%#Eval("ProductID") %>' modified='<%#Eval("ModifiedOn")%>' />

and try this jQuery (not tested):

$(document).ready(function() {
  $("span[id*=Countdown_]").each( function() {
     var id = $(this).attr("id");
     var modified = $(this).attr("modified");

     GetTimeOnLoad(modified, id);
  });
});


The onLoad event is never fired by a span tag. You can trigger the execution of your method inside $(document).ready();

  $(document).ready(function() {
      //put your call here...
  });
0

精彩评论

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

关注公众号