Ich habe eine .net-Web-Formular-Methode, um die JavaScript-Methode (von einem Benutzersteuerelement) in einem Anruf aufzurufen, aber nur der erste Anruf ausgelöst wird. Der Back-End-Codes ist:JavaScript Methodenaufruf nur einmal mit ScriptManager aufgerufen werden
bool isAddOnsExisting = priceSummaryList.Any(x => x.ItemName == "AAA");
UcSummary.setPanelVisibility(isAddOnsExisting, "AAAPanel");
bool isControlExisting = priceSummaryList.Any(x => x.ItemName == "BBB");
UcSummary.setPanelVisibility(isControlExisting, "BBBPanel");
Das Verfahren von Back-End 'UcSummary' ist:
public void setPanelVisibility(bool isExisting, string itemTitle)
{if (isExisting)
{ScriptManager.RegisterStartupScript(Page, GetType(),
"setVisibility","updatePanelVisibility('1','" + itemTitle + "');", true);}
else
{ScriptManager.RegisterStartupScript(Page, GetType(),
"setVisibility","updatePanelVisibility('0', '" + itemTitle + "');", true);}}
Die JavaScript-Methode ist:
function updatePanelVisibility(isExisting, itemPanel)
{
var theItemPanel = "#" + itemPanel;
if (isExisting == '1') {
$(theItemPanel).fadeIn();
}
else {
$(theItemPanel).hide();
}
}
ich nur die erste Methode gefunden 'AAA' wird ausgelöst, aber 'BBB' wird ignoriert. Könnte jemand den Grund angeben? Vielen Dank!
Ich habe die Berufung Methode geändert: if (isExisting) { ScriptManager.RegisterClientScriptBlock (Seite, GetType(), "setControlVisibility2", "updateControlPanelVisibility ('1', '" + itemTitle + "'); ", wahr); } sonst { ScriptManager.RegisterClientScriptBlock (Seite, GetType(), "setControlVisibility3", "updateControlPanelVisibility ('0', '" + itemTitle + "');", true); } Es läuft immer noch nur einmal für AAA. – DennisL
Ich füge den Schlüssel als "Script" + Guid.NewGuid(), dann funktioniert es! Vielen Dank! – DennisL