2011-04-02 67 views
0

嗨我似乎無法得到這個工作:DIV通過重定向代碼背後

div.Attributes.Add("UserFriendsWall.aspx?FriendID=" + Server.UrlEncode(id)); 

也tryed這一點:

div.Attributes.Add("onclick", "UserFriendsWall.aspx?FriendID=" + Server.UrlEncode(id)); 

反正同時存儲id來重定向?

也許

div.Attributes.Add("onclick", "redirect(" + id + ");"); 

這只是一種手段,如果沒有與C#沒有其他辦法

<script type="text/javascript"> 
    function redirect(id) { 
     redirct function via javascript maybe, dont know how tho?('DivClicked', id); 

    } 


</script> 
+1

你能解釋一下你認爲代碼應該做什麼嗎? – Bjorn 2011-04-02 19:46:16

+0

以及我需要「在」點擊一個div重定向我,併爲我編碼的ID也許一些JavaScript可能能夠做到這一點不確定,至於代碼,這是我的嘗試在做這個 – 2011-04-02 19:49:47

回答

2

我想你想要的是

div.onclick = function() { 
    location = "UserFriendsWall.aspx?FriendID=" + encodeURIComponent(this.id); 
}; 

或者,如果id是在本地範圍內的變量,從前面掉落this.

+0

謝謝邁克!工作完美 – 2011-04-02 20:09:35

0

我不知道這是否會解決你的問題,但你需要告訴它應該重定向的JavaScript,即:window.location.href="UserFriendsWall..."。此刻你只是傳遞一個字符串,它什麼都不做。