this is a little bit difficult question
I have asp:button ,inside a repeater
<asp:button id="tdb1" commandname="update" text=update runat=server ></asp:button>
under this button there is a jquery line script, that determine the classes of the button.
like this:
<script type="text/javascript">
$("#<%=tdb1.ClientID%>").button({icons:{primary:"ui-icon-refresh"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");
</script>
I am getti开发者_StackOverflowng error from the compailer : Name 'tdb1' is not declared.
if I change the button to regular button(not asp)the jquery works just fine ,but then I can't capture the event of the button, on server side.
What can I do?
Thanks for any help
One thing I've learned using .NET is that you're better of using class names for everything. Using IDs will drive you mad because .NET wants to own them all.
This is because the code tdb1.ClientID
is looking for a tdb1
control outside of your repeater.
As @Diodeus has stated, you are best to use classes with ASP.NET jQuery like:
<asp:button class='<%#String.Format("tdb_{0}", Container.ItemIndex)%>' id="tdb1" commandname="update" text="update" runat="server"></asp:button>
<script type="text/javascript">
$('<%#String.Format(".tdb_{0}", Container.ItemIndex)%>').button({icons:{primary:"ui-icon-refresh"}}).addClass("ui-priority-secondary").parent().removeClass("tdbLink");
</script>
You can't find the button because it's nested in the repeater. You could try setting the style in the code behind in ItemDataBound, or you could possibly leverage the client onload event of the button.
If you want to access all buttons, try:
<asp:button CssClass="foo" ... />
And then
$('#repeaterId .foo').button(...).addClass(...); // etc.
精彩评论