Question

I'm trying to use Telerik's RadSpell to spellcheck some text when the user submits it.

The way this is supposed to work is by stopping the postback, triggering the spellcheck through javascript, then in the spellcheckfinished event manually starting the real postback. The problem is that in the last step the Clicked event isn't firing for the button and the server side event handler never gets called.

Here is the relevant .aspx code:

<script type="text/javascript" language="javascript">

    var spellCheckFinished = false;
    var btnClicked;

    function doSpellCheckStuff(btnTrigger) 
    {          
        btnClicked = btnTrigger;
        var spell = GetRadSpell('<%= rsMessage.ClientID %>');
     //   spell.add_clientCheckFinished(checkFinished);
        spell.startSpellCheck();
        return false;
    }

    function checkFinished(sender, args)
    {   
        args.SuppressCompleteMessage = true;
        setTimeout('MySubmit();', 100);
    }

    function MySubmit()
    {
        WebForm_DoPostBackWithOptions(
            new WebForm_PostBackOptions(btnClicked.id, '', true, '', '', false, true)
        );
    }
</script>

<tr>
            <td>
                <asp:Button ID="btnSubmit" OnClientClick="return doSpellCheckStuff(this);" Text="Submit" 
                            OnClick="btnSubmit_Click" runat="server" />
            </td>
            <telerik:RadSpell   ID="rsMessage" ControlToCheck="txtMessage" ButtonType="None" 
                                UseClassicDialogs="true" FragmentIgnoreOptions="All" 
                                OnClientCheckFinished="checkFinished" runat="server" />
        </tr>

Any idea why btnSubmit_Click isn't getting called and how I can fix it?

Was it helpful?

Solution

Try to inject your postback script as :

string script = @"function MySubmit(){" +
                  this.Page.ClientScript.GetPostBackEventReference(myButton, string.Empty);
                  "}";

if (!this.Page.ClientScript.IsClientScriptBlockRegistered("myPostBackScript"))
{
    this.Page.ClientScript.RegisterClientScriptBlock(typeof(MyPage), "myPostBackScript", script, true);
}

OTHER TIPS

The last like of doSpellCheckStuff() is returning false always, which stops the OnClick event listener from running.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top