Я зарегистрировал блок сценария с всплывающим окном jQuery при нажатии элемента класса. Скрипт полностью зарегистрирован, но всплывающее окно не открывается при нажатии элемента класса.
Ниже кода зарегистрирован скрипт в С#, и я хочу вызвать всплывающее окно при нажатии класса my_modal_open
public void RegisterScript()
{
string script = @"function DownloadFiles() {alert('fds');
$('#my_modal').width('auto');
$('#my_modal').popup({
'autoopen': true,
'reposition': true,
'autozindex': true
});
return false;
}
$(document).ready(function () {
$('.my_modal_open').click(function () {
$('#my_modal').popup({
'autoopen': true,
'reposition': false,
'autozindex': true
});
});
});
";
//ScriptManager.RegisterStartupScript(this, this.GetType(), "RegisterClientScriptBlock", script, true);
this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "RegisterClientScriptBlock", script, true);
}
Ниже представлен HTML-формат открытого всплывающего окна в iframe
<div id="my_modal" class="well" style="display: none; width: auto; z-index: 1000;">
<a href="#" class="my_modal_close" style="float: right; padding: 0 0.4em;">×</a>
<iframe name="frDownloadFiles" runat="server" id="frDownloadFiles" src="about:blank"
frameborder="0" width="auto" scrolling="no" style="min-height: 300px;"></iframe>
</div>
Ниже код вызывает функцию и задает формат всплывающего окна.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindControl();
frDownloadFiles.Attributes.Add("src", "../DownloadDataPackFiles.aspx?DataPackageID=" + CurrentDataPackages.Id.ToString());
RegisterScript();
}
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "RegisterClientScriptBlock", script, true);
Используйте RegisterStartupScript
для вызова javascript в pageload
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindControl();
frDownloadFiles.Attributes.Add("src", "../DownloadDataPackFiles.aspx?DataPackageID=" + CurrentDataPackages.Id.ToString());
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(),"RegisterScript" ,"RegisterScript();");
}
}
Использовать RegisterStartupScript в Pageload
Примечание. Не забудьте указать simicolon RegisterScript();