我想要一个文本框就像一个“发布它”或“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