ページにまだレンダリングされていないコントロールに 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);
}
}