分類
Telerik

[Telerik] The control with ID ‘xxx’ requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

Situation

在.aspx 宣告 telerik:RadAjaxManager 前未先建立 telerik:RadScriptManager
Source Code 如下

    <!--RadScriptManager應該在RadAjaxManager前建立
    <telerik:RadScriptManager ID="RadScriptManager_Main" runat="server">
    </telerik:RadScriptManager>
    -->
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadButton1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadLabel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Action

在建立telerik:RadAjaxManager之前先建立telerik:RadScriptManager

    <telerik:RadScriptManager ID="RadScriptManager_Main" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadButton1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadLabel1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Result

不再出現
The control with ID ‘RadAjaxManager1’ requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

分類
Telerik

[Telerik] 如何處理匯出檔案(Excel)中的Leading Zeros

Leading Zero : 在Excel中輸入0開頭的內容時,0會自動忽略。
同理,使用Telerik匯出檔案(.xls)時若開頭為0的內容也也會自動忽略開頭0。如下方在網頁中顯示的電話欄位

在網頁上顯示的很正常,在DB的資料也是一模一樣的內容。
但匯出檔案後在檔案中(.xls)就會發生 Leading Zero。如下

解決的方式也很簡單,在匯出檔案前先對內容作處理,如下

protected void UserDataGrid_ExportCellFormatting(object sender, ExportCellFormattingEventArgs exportCellData)
{
	string uniqueNameInColumn = exportCellData.FormattedColumn.UniqueName;
	string textInColumn = exportCellData.Cell.Text;
	//avoid leading zero in export file(.xls)
	exportCellData.Cell.Text = String.Format("&nbsp;{0}", textInColumn);
}

其中UserDataGrid_ExportCellFormatting方法為Telerik:RadGrid的事件觸發方法,在匯出檔案前會先觸發該方法。

<telerik:RadGrid OnExportCellFormatting="UserDataGrid_ExportCellFormatting" ...>

重點為在方法中透過String.Format轉換內容

	//avoid leading zero in export file(.xls)
	exportCellData.Cell.Text = String.Format("&nbsp;{0}", textInColumn);

如此在匯出檔案中就可避免Leading Zeros。
 

分類
Telerik

[Telerik] 在匯出檔案前調整 RadGrid Column 的 Cell 內容

需求如標題。
原因是操作者希望在網頁看到的和匯出檔案的是兩回事。(但這兩回事必須存在某種規則)
好吧,基本上就是在匯出檔案之前做些手腳。
RadGrid提供OnExportCellFormatting事件,該事件會回呼到自定義方法讓我們可以在匯出檔案之前先對RadGrid的column內容作調整。如下

<telerik:RadGrid OnExportCellFormatting="UserDataGrid_ExportCellFormatting" ... >
接著在UserDataGrid_ExportCellFormatting方法中做手腳!!
protected void UserDataGrid_ExportCellFormatting(object sender, ExportCellFormattingEventArgs exportCellData)
{
	string uniqueNameInColumn = exportCellData.FormattedColumn.UniqueName;
	string textInColumn = exportCellData.Cell.Text;
	switch (uniqueNameInColumn)
	{
		case "Name":
			exportCellData.Cell.Text = textInColumn + 1;
			break;
		case "ID":
			exportCellData.Cell.Text = textInColumn + 2;
			break;
	}
}
值得注意的是可以從 ExportCellFormattingEventArgs 取得相對應的資訊。如上方的
1.FormattedColumn.UniqueName 會對應的 column 的 unique name。透過這個unique name來確認是哪個 column
2.Cell.Text 則是該 column 的 cell 內容,就是修改這個值來達到匯出檔案不同於網頁內容的要求。
如上就是對column名稱為Name的cell內容+1,對column名稱為 ID 的 cell 內容+2
分類
Telerik

[Telerik] 在匯出檔案中顯示Display為false的column

有時候在RadGrid的Column會設定 Display="false" 讓column隱身。如下

<telerik:GridBoundColumn Display="false" DataField="VT00" HeaderText="VT00" UniqueName="VT00" >
</telerik:GridBoundColumn> 

但這些隱身的column也不會出現在匯出的檔案中。
官方的解法是在匯出之前將這些隱身column的Display設為true即可。如下

protected void ExportButton_Click(object sender, EventArgs e)
{
    UserDataGrid.MasterTableView.GetColumn("VT00").Display = true;
    UserDataGrid.MasterTableView.ExportToExcel();
}

 

分類
jQuery Telerik

使用jQuery取得Relerik:RadComboBox的值

其實就跟取得一般UI元件的值相同。步驟如下

1.從網頁的source code確定該UI的正確ID
2.使用jQuery透過UI的正確ID並取值

網頁畫面如下,UI元件是telerik:RadComboBox。需求是透過jQuery取得”請輸入學校”的值

.aspx


<div id="ctl00_MainContent_cboFirstColleges" class="RadComboBox RadComboBox_Default" minlength="2" style="width:250px;white-space:normal;">
	<table summary="combobox" style="border-width:0;border-collapse:collapse;width:100%">
		<tbody><tr>
			<td class="rcbInputCell rcbInputCellLeft" style="width:100%;"><input name="ctl00$MainContent$cboFirstColleges" type="text" class="rcbInput radPreventDecorate valid" id="ctl00_MainContent_cboFirstColleges_Input" value="憭批?憭批飛" autocomplete="off" aria-invalid="false"></td><td class="rcbArrowCell rcbArrowCellRight"><a id="ctl00_MainContent_cboFirstColleges_Arrow" style="overflow: hidden;display: block;position: relative;outline: none;">select</a></td>
		</tr>
	</tbody></table><input id="ctl00_MainContent_cboFirstColleges_ClientState" name="ctl00_MainContent_cboFirstColleges_ClientState" type="hidden" autocomplete="off" value="{&quot;logEntries&quot;:[],&quot;value&quot;:&quot;&quot;,&quot;text&quot;:&quot;隢撓?亙飛??quot;,&quot;enabled&quot;:true,&quot;checkedIndices&quot;:[],&quot;checkedItemsTextOverflows&quot;:false}">
</div>

其中ctl00_MainContent_cboFirstColleges就是UI的ID。接下來就是使用jQuery

透過ID取得值。

.cs

function CheckUserHighestEducationSchool() {
	let userHighestEducationSchool = $("#ctl00_MainContent_cboFirstColleges").val();
}

userHighestEducationSchool就是存放”請輸入學校”。