开发者

Selecting an element without an Id

开发者 https://www.devze.com 2022-12-10 06:41 出处:网络
I\'m trying to select an element from my webpage... I have inserted a control into my page and i need to set some values an element inside the control at pageload from c# code.. The thi开发者_如何学

I'm trying to select an element from my webpage...

I have inserted a control into my page and i need to set some values an element inside the control at pageload from c# code.. The thi开发者_如何学JAVAng is, as soon as I insert the control into the page... A prefix is appended to the id name... Because of that new name, my css definition won't be appended...

Is there any way to access this element from C# without the need to make it an Id?

Edit: To clarify what Im trying to do here. Im trying to make a generic control, which gets a width and height set to it's parameters. I need to set this manually to the element by adding a style attribute. I can't make the element an id, because this will stop the possibility of making it generic.

This is whats inside of the control... the fact is, I need the imageRotatorDiv to be a class instead of an id. Otherwise i can't use multiple image rotators on one page.

But how can I select a class in a page from c# code? Is it possible?

<div id="imageRotatorDiv" runat="server">
   <div class="imageRotator">
    <asp:Repeater ID="rprImages" runat="server">
        <ItemTemplate>
            <asp:Image ID="imgItem" runat="server" />
        </ItemTemplate>
    </asp:Repeater>
   </div>
</div>


you can define your style to a class name instead of id.

<asp:TextBox ID="MyText" CssClass="someclass" runat="server" />

html output

<input type="text" id="Something_MyText" class="someclass" />

css

.someclass { border:solid 1px red; }


In JQuery :

$("div[id$=MyDiv]").addClass("myDiv")

And you just need to define the myDiv CSS class. Or, to modify directly the style :

$("div[id$=MyDiv]").css("font-size", "14px");

JQuery details

0

精彩评论

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