2013-01-16 32 views
0

我有,我定義的代碼屬性後面如下ASP.NET頁面違約隱藏字段值:使用內聯服務器代碼

public int testProperty { get; set; } 

在我的網頁我定義了一個隱藏字段,並要設置的重視使用在線服務器代碼如下:

<asp:HiddenField ID="hftestProperty" runat="server" Value="<%= testProperty.ToString() %>" /> 

我遇到的問題是,當控制在瀏覽器呈現,它呈現值I定義它以同樣的方式:

<input type="hidden" name="hftestProperty" value="<%= testProperty.ToString() %>"> 

任何想法爲什麼會發生這種情況?

回答

1

嘗試這樣的:

<input id="hftestProperty" type="hidden" value="<%=testProperty.ToString()%>" /> 

它渲染:

<input id="hftestProperty" type="hidden" value="0" /> 
+0

這正是我需要的...謝謝你 – malkassem

1

你將不得不設置隱藏字段的值在後面的代碼,例如在Page_Load事件:

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
    hftestProperty.Value = testProperty.ToString(); 
    } 
} 
+0

該做的工作,但我希望用做內聯服務器端代碼。謝謝 – malkassem

0

您可能需要將testProperty轉換爲隱藏字段的字符串。如果您要在服務器上使用testProperty的字符串值,那麼testProperty.ToString()將始終可供您使用。

嘗試下面的代碼:

<input type="hidden" id="hftestProperty" value="<%= testProperty%>" /> 

欲瞭解更多信息,你可以看到這個question.

相關問題