0

my button on server works on alertMsg() how ever doesnt work on playSelected()

my button on Html works on playSelected() and alertMsg()

anyone can figure out for me why?

javascript

function playSelected() {

    var a = "Video/" + document.getElementById("TextBox2").value + ".flv";

    jwplayer("mediaplayer").setup({

        flashplayer: "jwplayer/player.swf",

        file: a,

        image: "jwplayer/preview.jpg"
    });
}


function alertMsg() {
    alert("testing123");
}

button in html

input type="button" runat="server" value="Click me!" onclick='playSelected()'

button in server

asp:Button ID="Button2" runat="server" text="call javascript" OnClientClick="playSelected(); return true;" UseSubmitBehaviour="false"

1
  • If you use Attributes.Add(), you should use 'onclick' rather than the 'onclientclick' that you use in the aspx markup. Commented Feb 5, 2012 at 13:45

2 Answers 2

1
<asp:Button runat="server" 
            OnClientClick='playSelected(); return true;' 
            UseSubmitBehaviour="false" />
Sign up to request clarification or add additional context in comments.

6 Comments

ya,it is added and it is the same,button in my page doesn't work
remove onclick because it will cause a full postback
removed, doesnt work too, i can use button on server to call alertFunction() but it doesnt work on my playSelected()
What exactly do you mean by "doesn't work", in particular: do you get any javascript errors? Also: what is the html for that button (do a 'view source'), do you see the correct javascript call there?
You don't need this anymore: Button2.Attributes.Add("OnClientclick", "playSelected()");.Also is not doing what you think it does, it should be "onclick" instead of "OnClientClick". Did you check UseSubmitBehaviour property?
|
0

Make sure your java script is allowed on the clietn browser. Also do postbacks logic in your page_load event. I would rather create the Button on overriden CreateChildControls method of the page, and on overriden OnPreRender wireup my java script and register the script with ClientScriptManager method RegisterStartupScript. So that you can have nice page life cycle control.

Comments

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.