views:

472

answers:

2

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?

+2  A: 

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

SquidScareMe
So then how do I stop the postback to wait for the spellcheck and restart it after?
Telos
try returning true instead of false and see what happens.
SquidScareMe
If I return true it will immediately postback, which will prevent the spellchecker from running. That's why I added return false in the first place...
Telos
sorry about that. I'm glad ScarletGarden could help you, though.
SquidScareMe
+3  A: 

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);
}
Canavar
That did it with one minor change, add true to the end of RegisterClientScriptBlock... otherwise it just injects the text into your page and isn't considered a script. Thanks!
Telos
yes, I forgot to add bool to add script tags, updating it now.
Canavar
This was very helpful, thank you!
Rich Andrews