簡體   English   中英

在來自母版頁控件的內容頁中的變量后面的asp.net代碼上設置jQuery選擇器

[英]Set jQuery selector on asp.net code behind variable in Content Page that comes from a Master Page control

我有一個位於母版頁上的ASP LinkBut​​ton控件。 在一個內容頁面上,當用戶從某個頁面進入該頁面時,我想為該元素設置滾動到動畫。

我想做的是基於VB.net字符串變量(從控件的ID設置)動態設置jQuery選擇器

ContentPage.aspx:

$('body').animate({
    scrollTop: $('#<%= scrollToControl %>').offset().top + 'px'
}, 500, 'swing');

ContentPage.aspx.vb

Dim scrollToControl As String = CType(Master.FindControl("someControl"), LinkButton).ClientID

這是獲取ID,但是當我嘗試更新ContentPage.aspx時得到

scrollToControl is not declared. It may be inaccessible due to its protection level

PS我應該完全從后面的代碼中添加jQuery代碼,而不是僅更改選擇器嗎?

您的問題是Dim實際上將某些內容聲明為私有。 嘗試使用ProtectedPublic聲明字符串。

Protected scrollToControl As String = CType(Master.FindControl("someControl"), LinkButton).ClientID

希望有幫助!

另外,關於您的PS:這樣做的方式或使用RegisterClientScriptBlock從代碼隱藏的方式都很好(imho)。 我認為這取決於個人偏好,建議您保持一致。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM