2013-08-16 90 views
-1

我已經在C#中編寫了一個項目,如果在項目使用過程中發生事件,我將加載HTML網頁。C# - 將值發送到HTML中的HREF

我的問題是,在我的html頁面,我有一個標籤內A HREF節點例如:

<a href="http://pseudo01.hddn.com/vod/demo.flowplayervod/flowplayer-700.flv" 
      style="display:block;width:inherit;height:inherit;background-color: black;overflow:hidden" 
      id="player"> 
     </a> 

我想通過發送C#變量(稱爲myHrefFile)編程改變href的值取決於關於用戶做了什麼。

這怎麼辦?

+0

Ajax調用可能使用傑森也許使用Web API http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first- web-api –

+0

Asp.Net?的WinForms? WPF? – I4V

+0

或看看http://stackoverflow.com/questions/5194268/replace-item-prices-in-html-tags-from-json-data –

回答

0

你可以做這樣的事情

<a href="<%= someMethodThatGetHrefValue() %>" 
style="display:block; width:inherit;height:inherit; background-color:black; 
overflow:hidden" 
id="player">click</a> 

調用決定什麼應該HREF鏈路的方法。

,並把這樣的

public string someMethodThatGetHrefValue() 
{ 
    if(someval == true) 
     return "http://www.google.com"; 
    else 
     return "http://www.yahoo.com"; 
} 
+0

它看起來很有希望,但由於某種原因,當我有一個消息框讀取href一旦它被加載,它認爲該網址是:「http://where_my_page_is.com/<%= someMethodThatGetHrefValue()%>」 - ----要清楚:我把C#代碼放在包含瀏覽器的窗口中。那是錯的嗎? – touyets

+0

如果有可能使用絕對url然後使用它。像http://www.domain.com/somepage.aspx –

0

像這樣的事情也許是方法決定的href的所有邏輯?這是一個Asp.net解決方案。

<asp:LinkButton ID="LinkBut" runat="server" onclick="LinkBut_Click">Click here</asp:LinkButton></p> 

protected void LinkBut_Click(object sender, eventArgs e) 
{ 

    string myHrefFile = ""; 

    if(Value.equals(true)) 
    { 
    myHrefFile = "page1.aspx"; 
    } 
    else 
    { 
     myHrefFile = "page2.aspx"; 
    } 

     Response.Redirect(myHrefFile); 
}