2009-04-08 57 views
1

我在使用腳本時出現問題,該腳本在文本區域位於Ajax選項卡內時將NiceEdit工具欄添加到文本區域。如何引用Ajax選項卡中存在的控件?

我想知道我是否應該是指它以不同的方式不僅僅是ID。

我的意思是文本區域的ID,我試圖把標籤集裝箱外的文本區域,它的工作原理,但是當我回到它,它根本沒有。

<%@ Page Language="VB" ValidateRequest ="false" AutoEventWireup="false" CodeFile="tabbedNiceEditt.aspx.vb" Inherits="Client_tabbedNiceEditt" %> 
<script src="../nicEdit/nicEdit.js" type="text/javascript"></script> 

<script type="text/javascript"> 
bkLib.onDomLoaded(function() { 
new nicEditor({buttonList : ['fontSize','fontFamily','fontFormat','bold','italic','underline','strikethrough','forecolor','bgcolor','removeformat'], iconsPath : '../nicEdit/nicEditorIcons.gif'}).panelInstance('txt'); 
}); 
</script> 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title>Untitled Page</title> 
    <script type="text/javascript"> 

     function pageLoad() { 
     } 

    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 

    <div> 


     <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     <cc1:TabContainer ID="TabContainer1" runat="server"> 
     <cc1:TabPanel ID= "first" runat ="server" > 
     <ContentTemplate> 
     <b>Stuff Goes HERE</b> 
     <br /> 
     <asp:TextBox ID = "txt" name = "txt" runat ="server" TextMode ="MultiLine" Height = "256" Width = "256"> 
     </asp:TextBox> 
     <br /> 
     <br /> 
     <asp:Button id = "btn" runat ="server" Text = "click" /> 
     </ContentTemplate> 
     </cc1:TabPanel> 
     <cc1:TabPanel ID = "second" runat ="server" > 
     <ContentTemplate> 
     <b>More Stuff for second tab</b> 
     </ContentTemplate> 
     </cc1:TabPanel> 
     </cc1:TabContainer> 
    </div> 
    </form> 
</body> 
</html> 

回答

2

txt是你控制的服務器 ID,您必須使用客戶 ID:

....panelInstance('<%= txt.ClientID %>'); 

基本上,客戶機ID由服務器ID派生和命名容器在哪裏控制,以避免任何命名衝突。當您的文本區域不在Ajax選項卡中時,客戶端ID與服務器ID相同。當您將文本區域放在Ajax選項卡中時,它的客戶端ID不同(您可以通過在瀏覽器中查看頁面源來檢查它)。


編輯:

從馬

I viewed the page in browser, checked the ID in the page source, it was "TabContainer1$first$txt", used it instead of "txt" and the script was like: panelInstance('<%= txt.TabContainer1$first$txt %> I got an error: BC30456: 'TabContainer1' is not a member of 'System.Web.UI.WebControls.TextBox'.

那不是我的意思是:你必須把panelInstance('<%= txt.ClientID %>')在你的源代碼,並asp.net將轉換,爲panelInstance('TabContainer1$first$txt')

我告訴你檢查在Web瀏覽器頁面的源代碼只是爲了看到客戶端1d不再名爲「txt」,但它是從服務器的ID和命名容器構造。

+0

我在瀏覽器中查看了頁面,在頁面源代碼中檢查了ID,它是「TabContainer1 $ first $ txt」,用它代替「txt」,腳本如下所示: panelInstance('<%= txt。 TabContainer1 $ first $ txt%> 我得到一個錯誤: BC30456:'TabContainer1'不是'System.Web.UI.WebControls.TextBox'的成員 – Maen 2009-04-08 08:40:57

相關問題