質問

I am trying to add buttons programmatically to a page and when they are clicked I want to call a function in the parent (the buttons are in a jQuery dialog) the function works fine because I have been using it another way too but I am having problems adding the JS to the onClientClick from the code-behind.

btnLink.OnClientClick = "window.parent.openlink(http://www.google.co.uk, test, 300, 300);return false;";

I have looked in developer tools and it isnt setting the onclientclick but instead using onclick, I don't know if this causes a problem.

This is an example of a button on the parent page and how it is generated (working model):

<input name="btnOpen" class="DataControlButtons" id="btnOpen" onclick="openlink('CustomerTypes-Open.aspx', 'Open', '1000', '470'); return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;btnOpen&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" type="submit" value="Open">

This is how the non-working button is generated:

<input name="ctl02" onclick="window.parent.openlink(http://www.google.co.uk, test, 300, 300);return false;" type="submit" value="Configuration">
役に立ちましたか?

解決

The function string parameters lack quotes, making this call an invalid javascript. Try turning them into valid strings:

btnLink.OnClientClick =
    "window.parent.openlink('http://www.google.co.uk', 'test', 300, 300);return false;";
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top