0
votes

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"

2
If you use Attributes.Add(), you should use 'onclick' rather than the 'onclientclick' that you use in the aspx markup. - Hans Kesting

2 Answers

1
votes
<asp:Button runat="server" 
            OnClientClick='playSelected(); return true;' 
            UseSubmitBehaviour="false" />
0
votes

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.