Я создаю динамические ссылки через ретранслятор и привязываю ссылки с сервера по адресу OnPreRender. Но окно цвета работает только после первого щелчка. Я использую live для привязки динамических ссылок.Colorbox, работающий над вторым щелчком
Код следующим образом:
protected virtual void BindJQuery()
{
string jquery = string.Empty;
jquery = StoreLocation() + "Scripts/jui/jquery-1.8.0.min.js";
Page.ClientScript.RegisterClientScriptInclude(jquery, jquery);
}
protected virtual void BindColorBox()
{
string jquery = null;
jquery = StoreLocation() + "Scripts/colorbox/jquery.colorbox-min.js";
Page.ClientScript.RegisterClientScriptInclude(jquery, jquery);
}
protected void BindColorBoxC()
{
StringBuilder urlScript = new StringBuilder();
urlScript.AppendLine("<script type=\"text/javascript\">");
urlScript.AppendLine("$('.iframeC').live('click',function(e){ e.preventDefault(); $(this).colorbox({width: '660px', height: '416px', iframe: true}); });");
urlScript.AppendLine("</script>");
string js = urlScript.ToString();
Page.ClientScript.RegisterClientScriptBlock(GetType(), "colorboxC", js);
}
protected override void OnPreRender(EventArgs e)
{
BindJQuery()
BindColorBox();
BindColorBoxC();
base.OnPreRender(e);
}
Edit:
я заменил следующую строку:
urlScript.AppendLine("$('.iframeC').live('click',function(e){ e.preventDefault(); $(this).colorbox({width: '660px', height: '416px', iframe: true}); });");
С:
urlScript.AppendLine("$(document).on('click','.iframeC',function(e){ e.preventDefault(); $(this).colorbox({width: '660px', height: '416px', iframe: true}); });");
Но результат такой же. Он по-прежнему не работает при первом нажатии. И нет наложения, потому что это новая загрузка страницы.
Любые виды помощи приветствуются. Заранее спасибо.
Он по-прежнему работает после первого щелчка :( – Prakash