我想要一個文本框就像一個「發佈它」或「Stiff備忘錄」就像小部件Igoogle或Windows 7部件。C#使用文本框作爲「發佈」/「粘滯便箋」客戶端事件
的想法
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
每當用戶鍵入到文本框中它調用javascript來保存文本到餅乾。
有人能給我一個提示嗎?
我想要一個文本框就像一個「發佈它」或「Stiff備忘錄」就像小部件Igoogle或Windows 7部件。C#使用文本框作爲「發佈」/「粘滯便箋」客戶端事件
的想法
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
每當用戶鍵入到文本框中它調用javascript來保存文本到餅乾。
有人能給我一個提示嗎?
這有點快而骯髒,但會讓你去。
網絡上有很多setCookie/getCookie JS片段。我用這些:
http://www.dotnetspark.com/kb/1480-use-cookies-javascript-getcookie-setcookie.aspx
現在德代碼:
<input type="text" id="txtMemo" />
<script type="text/javascript">
function setCookie(CookieName, CookieVal, CookieExp, CookiePath, CookieDomain, CookieSecure)
{
var CookieText = escape(CookieName) + '=' + escape(CookieVal); //escape() : Encodes the String
CookieText += (CookieExp ? '; EXPIRES=' + CookieExp.toGMTString() : '');
CookieText += (CookiePath ? '; PATH=' + CookiePath : '');
CookieText += (CookieDomain ? '; DOMAIN=' + CookieDomain : '');
CookieText += (CookieSecure ? '; SECURE' : '');
document.cookie = CookieText;
}
// This functions reads & returns the cookie value of the specified cookie (by cookie name)
function getCookie(CookieName)
{
var CookieVal = null;
if(document.cookie) //only if exists
{
var arr = document.cookie.split((escape(CookieName) + '='));
if(arr.length >= 2)
{
var arr2 = arr[1].split(';');
CookieVal = unescape(arr2[0]); //unescape() : Decodes the String
}
}
return CookieVal;
}
var memoCookieName = "txtMemo_value";
var memoElementId = "txtMemo";
var memoElement = document.getElementById(memoElementId);
memoElement.value=getCookie(memoCookieName);
memoElement.onkeyup = function() {
setCookie(memoCookieName,this.value, new Date(new Date().getTime()+1000*60*60*24*30));
};
</script>
這將普通的HTML工作。在你使用ASP.NET標記和控件的情況下,ID屬性有不同的含義,所以你需要讓你的JS知道實際的客戶端ID。例如:
(...)
var memoCookieName = "txtMemo_value";
var memoElementId = "<%= TextBox1.ClientID %>";
var memoElement = document.getElementById(memoElementId);
(...)
當然。遊戲以「改變」事件:
它只是利用這一事件,並更新您以前使用JavaScript創建過一些餅乾。
到目前爲止,您有哪些代碼和研究? – BugFinder 2011-05-20 11:59:46
如果我在你的鞋子,我會尋找「asp.net + ajax」 – 2011-05-20 12:02:28
到目前爲止你有什麼?告訴我們你的代碼。 – 2011-05-20 13:26:23