This is a migrated thread and some comments may be shown as answers.

RegisterStartupScript not run script

2 Answers 198 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dominik
Top achievements
Rank 1
Dominik asked on 09 May 2012, 01:15 PM
Hello,

I have following scenario.

On the Form I have RadButton with code:
protected void RadButton_tab_Click(object sender, EventArgs e)
        {
               sesja="abcdef";
               ScriptManager.RegisterStartupScript(Page, typeof(Page), "runTabelka", "openTabelka('"+sesja+"')", true);
        }
where openTabelka is javascript function located in body Form:
<telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
    <script type="text/javascript">
        function openTabelka(args) {
            var adres = "http://127.0.0.1/Tabela.aspx?" + args;
            window.open(adres, "_blank");
        }
    </script>
</telerik:RadScriptBlock>
next, I have script for key pressed on the Form:
function klik() {
            var k = event.keyCode;
            if (k == 13) {
                var button = $telerik.findButton("<%= RadButton_tab.ClientID %>");
                button.click();
            };
        }
and in body tag: <body onkeypress="javascript:klik()">

when I click (with mouse button) on my RadButton, function openTabelka is running and new page in Web Browser is opened.
but when I press Enter key, function klik() is fired, RadButton (RadButton_tab_Click) is fired (I see this in debugger),
line with ScriptManager.RegisterStartupScript(Page, typeof(Page), "runTabelka", "openTabelka('"+sesja+"')", true); is executed,
 but script openTabelka is not running.
where I make a mistake ?

regards, Dominik

2 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 11 May 2012, 02:20 PM
Hello Dominik,

Please check the sample that I provided in your support ticket on the matter and verify if there are differences in the setup or if I have missed something, as I was unable to reproduce the reported problem.

For future use of our support system I would suggest creating a separate ticket or forum thread to report a particular problem, as this way the communication will be much easier to follow. That being said, let us continue our discussion in your support ticket on the matter. Once the problem is resolved, you can post the solution here if you wish, so that the community can benefit from it.

All the best,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Dominik
Top achievements
Rank 1
answered on 15 May 2012, 06:26 PM
thanks for the Slav for help in finding the error.

quote:
It appears that Internet Explorer automatically focuses the first button on the page, which is the ImageButton. As a result it is clicked on Enter key press and alters the logic that you have incorporated.
To prevent this behavior, please locate the ASP Panel control with ID Panel1 and set the RadButton as a DefaultButton like shown in the following code sample:
<asp:Panel ID="Panel1" runat="server" DefaultButton="RadButton_tab">
...
</asp:Panel>
Tags
General Discussions
Asked by
Dominik
Top achievements
Rank 1
Answers by
Slav
Telerik team
Dominik
Top achievements
Rank 1
Share this question
or