如何在回发发生后保持相同的文本框值 [英] How to maintain same textbox value after postback occured

查看:53
本文介绍了如何在回发发生后保持相同的文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题我已经问过了,但是现在有些事情我尝试过并再次提出来。 Plz帮助。



This question I already ask but now some things which I tried and again asking it. Plz help.

I trying to search the javascript as a option but my control are in DataGridview,
javascript function is:

var x;
function myFunction()
{
// var x = document.getElementById("suggchangeback");
//x.value = x.value.toUpperCase();

x = document.getElementById(document.getElementById(suggchangeback.ClientID)).value;
x.value = x.value.toUpperCase();
document.getElementById(document.getElementById(suggchangeback.ClientID)).value = x.value;
//return x.value;
}

I am using following script and calling it on onblur="myFunction()" 

<asp:TextBox ID="suggchangeback" runat="server" TextMode="MultiLine" EnableViewState="false" AutoPostBack="false" OnTextChanged="suggchangeback_Leave" onblur="myFunction()">

but flow control not going there.

and I want to store var x value from javascript function into the variable on .cs file. How to do this? please help..





我的尝试:



我试图搜索javascript作为选项但我的控件在DataGridview中,

javascript函数是:



var x;

函数myFunction()

{

// var x = document.getElementById(suggchangeback);

//x.value = x.value.toUpperCase();



x = document.getElementById(document.getElementById(suggchangeback.ClientID))。value;

x.value = x.value.toUpperCase();

document.getElementById(document.getElementById(suggchangeback.ClientID))。value = x.value;

//返回x.value;

}



我正在使用以下脚本并在onblur上调用它= myFunction()



< asp:TextBox ID =suggchangebackrunat =serverTextMode =MultiLineEnableViewState =falseAutoPostBack =false OnTextChanged =suggchangeback_Leaveonblur =myFunction()>



但流量控制不在那里。



我想将jx函数的var x值存储到.cs文件的变量中。这该怎么做?请帮助..



What I have tried:

I trying to search the javascript as a option but my control are in DataGridview,
javascript function is:

var x;
function myFunction()
{
// var x = document.getElementById("suggchangeback");
//x.value = x.value.toUpperCase();

x = document.getElementById(document.getElementById(suggchangeback.ClientID)).value;
x.value = x.value.toUpperCase();
document.getElementById(document.getElementById(suggchangeback.ClientID)).value = x.value;
//return x.value;
}

I am using following script and calling it on onblur="myFunction()"

<asp:TextBox ID="suggchangeback" runat="server" TextMode="MultiLine" EnableViewState="false" AutoPostBack="false" OnTextChanged="suggchangeback_Leave" onblur="myFunction()">

but flow control not going there.

and I want to store var x value from javascript function into the variable on .cs file. How to do this? please help..

推荐答案

人们可能会解释你特定于ASP.NET的所有方面,但我想建议更多的通用替代不可知的服务器端;它甚至可以在没有任何服务器端的情况下工作,当你只想恢复一些UI状态或任何数据之后,比如本地重新加载或任何其他需要恢复你以前状态的动作。



这个通用API是 Web存储

网络存储 - 维基百科,免费的百科全书 [ ^ ],

Web Storage API - Web API | MDN [ ^ ],

Window.sessionStorage - Web APIs | MDN [ ^ ],

Window.localStorage - Web APIs | MDN [ ^ ]。



显然,出于您的目的,您必须更喜欢会话存储,而不是本地存储。本地存储会污染您的本地浏览器数据,但即使使用本地存储,您也可以轻松将其删除。



另外,您可能更合适地希望保留所有状态记录一键并保存一次恢复所有内容。这将是最好的主意。为此,您需要序列化和反序列化所有数据。可以使用JSON轻松完成: JSON - JavaScript | MDN [ ^ ]。



您可以在我的文章的Web存储部分找到整个技术的全面样本:

JavaScript Calculator, 7动态严格模式切换和网络存储 [< a href =http://www.codeproject.com/Articles/890109/JavaScript-Calculator#a7target =_ blanktitle =New Window> ^ ]



就是这样。



-SA
People will probably explain your all aspects of it specific to ASP.NET, but I want to suggest more universal alternative agnostic to the server side; it can even work without any server side at all, when you simply want to restore some UI state or any data at all after, say, local reload or any other action which need restoration of your previous state.

This universal API is Web storage:
Web storage — Wikipedia, the free encyclopedia[^],
Web Storage API — Web APIs | MDN[^],
Window.sessionStorage — Web APIs | MDN[^],
Window.localStorage — Web APIs | MDN[^].

Apparently, for your purpose you have to prefer session storage, not local storage. Local storage would contaminate your local browser data, but even with local storage you can easily wipe it out.

Also, you may reasonably prefer keeping all the state record by just one key and save restore everything at once. It would be the best idea. To do so, you would need to serialize and deserialize all data. It can be easily done with JSON: JSON — JavaScript | MDN[^].

You can find a comprehensive sample of the whole technique in my article, in the Web storage section:
JavaScript Calculator, 7 Dynamic Strict Mode Switching and Web Storage[^]

That's all.

—SA


这篇关于如何在回发发生后保持相同的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆