0

ページにまだレンダリングされていないコントロールに jQuery を配線するにはどうすればよいですか? 次のメソッドをオーバーライドしようとしましたが、StepNavigationTemplateContainerID html マークアップがこのイベントでまだ使用できないため、機能しませんでした: Render、OnLoad、OnInit など

UpdatePanel を使用しているからでしょうか? UpdatePanel を使用しているときに、jQuery フックを発行できるようにするには、どのメソッド/イベントをオーバーライドできますか?

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    HookNextButton();
}       



void HookNextButton()
{
    string nextButtonClientId = wizardCooking.FindControl("StepNavigationTemplateContainerID").FindControl("btnNextStep").ClientID + "_lnkButton";
    var scriptKey = "Yo";

    string theScript =
        string.Format(
    @"
                    $(function() {{      


                        $('#{0}').click(function() {{
                            alert('hi');

                        }});

                    }});
                ", nextButtonClientId);
    Type cstype = this.GetType();

    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, scriptKey))
    {
        ScriptManager.RegisterStartupScript(
                this, this.GetType(), scriptKey, theScript, true);
    }


}
4

1 に答える 1

3

..を使用して委任し .on() ます。これにより、後でDOMに挿入される要素にイベントが関連付けられます..

$('body').on('click' , '#buttonid' , function() {
    // Your code here
    // This will handle the case of buttons that 
    // will be rendered later

});
于 2012-10-16T05:50:55.893 に答える