0

Got something like this:

    protected void Page_Init(object sender, EventArgs e)
    {
        LoadImageButtons();
    }

    private void LoadImageButtons()
    {
        for (int i = 1; i < 10; i++)
        {
            ImageButton myImageButton = new ImageButton();

            myImageButton .ID = i.ToString();
            myImageButton .CssClass = "buttonFieldClass";
            myImageButton .Click += new ImageClickEventHandler(einButton_Click);
            myImageButton .OnClientClick = "toRight(this.id);return false";

            div.Controls.Add(myImageButton);
        }
    }

Javascript (Jquery):

function toRight(id) {
$("#id").animate({ "left": "+=250px" }, "slow");};

and nothing happens (with static controls it works).. So I think something with the ID goes wrong.. Hope u guys can help me ..

4
  • did you try to alert the id that you get inside toRight ? just to check that you get a value? Commented Aug 4, 2011 at 10:13
  • did you check in view source, what written in client side ? Commented Aug 4, 2011 at 10:15
  • i am use "return toRight(this.id);" instead of "toRight(this.id);return false" Commented Aug 4, 2011 at 10:17
  • yea, i tried alert and I get the Id as well.. return toRight(this.id) dont works too Commented Aug 4, 2011 at 10:42

2 Answers 2

1

Change your jquery like this.

function toRight(id) {
    $("#" + id).animate({
        "left": "+=250px"
    }, "slow");
};

The string "#id" is not the desired selector.
The desired selector is "#" concatenated with the variable "id"

Sign up to request clarification or add additional context in comments.

2 Comments

thx 4 answer, but its still not moving.. i just click on the button, but nothing happens, there is also not a postback, (which is good I think)
ok think know why.. I cant move Imagebuttons, but Divs work ?! :(
0

Seems to me like your problem is this line

    myImageButton .OnClientClick = "toRight(this.id);return false";

Try changing to:

    myImageButton .OnClientClick = "toRight('" + this.id + "');return false";

Oh and the proposed Javascript fix is also correct and required!

3 Comments

it works if I change the controls to a Div.. Seems that you can't animate imagebuttons..
ImageButton renders as an <input> element in Html which is an inline element... giving it a "display: block" should do it (which is all the DIV is doing)
ok thx 4 the answer, perhaps I will try it (got now everthing in Divs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.