0

我知道有很多这样的问题。我尝试了很多,但仍然无法使其正常工作。

我有: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.

我已经尝试过:

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()窗口。

4

1 回答 1

2

您的 javascript 中应该出现语法错误!您的声明中有错字。

你写了:

  <script>
      fuction MyFunction(){
              alert('asdasd');
      }
  </script>

但它必须是:

  <script>
      function MyFunction(){
              alert('asdasd');
      }
  </script>
于 2013-01-08T12:14:54.220 回答