RegisterStartupScript not run script

3 posts, 0 answers
  1. Dominik
    Dominik avatar
    11 posts
    Member since:
    Oct 2011

    Posted 09 May 2012 Link to this post


    I have following scenario.

    On the Form I have RadButton with code:
    protected void RadButton_tab_Click(object sender, EventArgs e)
                   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 = "" + args;
      , "_blank");
    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 %>");
    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. Slav
    Slav avatar
    1359 posts

    Posted 11 May 2012 Link to this post

    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,
    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.
  3. Dominik
    Dominik avatar
    11 posts
    Member since:
    Oct 2011

    Posted 15 May 2012 Link to this post

    thanks for the Slav for help in finding the error.

    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">
Back to Top