我知道有很多这样的问题。我尝试了很多,但仍然无法使它工作。
我有:RadAjaxManager
,RadAjaxPanel
,RadScriptBlock
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
DefaultLoadingPanelID="RadAjaxLoadingPanel1">
<ClientEvents OnRequestStart="onRequestStart" />
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="AjaxPanel">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="AjaxPanel"/>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxPanel runat="server" ID="AjaxPanel" Wrap="True" CssClass="PanelAjax">
<telerik:RadComboBox runat="server" ID="cbLanguage" Width="115px"
AutoPostBack="True"Sort="Ascending" EmptyMessage="Choose language"
DataValueField="id" DataTextField="languageName"
OnSelectedIndexChanged="cbLanguage_SelectedIndexChanged">
</telerik:RadComboBox>
</telerik:RadAjaxPanel>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script>
function MyFunction(){
alert('asdasd');
}
</script>
</telerik:RadScriptBlock>
</asp:Content>
在Master Page
我有:
<telerik:RadScriptManager ID="ScriptManager1" runat="server">
</telerik:RadScriptManager>
我想在combo box selected index change
上运行MyFunction()。
我已经尝试过了:
protected void cbLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "myKey", "MyFunction();");
ScriptManager.RegisterStartupScript(Page, this.GetType(), "testOne", "MyFunction();", true);
}
我也试着直接发出警报:
ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('asd');", false);
RadAjaxManager1.ResponseScripts.Add(@"radalert('Welcome to RadWindow <b>Prometheus</b>!', 330, 210);");
string treeScript = "<script language='javascript'>alert('asd');</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", treeScript);
RadAjaxManager1.ResponseScripts.Add(@"alert('Welcome');");
有人可以解释一下我做错了什么吗?
没有错误。
只是javascript代码没有执行。我的屏幕上没有alert()
窗口。
答案 0 :(得分:2)
你的javascript中应该出现语法错误!您的声明中有拼写错误。
您写道:
<script>
fuction MyFunction(){
alert('asdasd');
}
</script>
但必须是:
<script>
function MyFunction(){
alert('asdasd');
}
</script>