Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This question I already ask but now some things which I tried and again asking it. Plz help.

C#
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..


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..
Posted
Updated 18-Apr-16 6:47am
Comments
ZurdoDev 18-Apr-16 12:48pm    
If it is in a grid, then save the data when the page posts back. Then when the grid binds again it will be in the data.

1 solution

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
 
Share this answer
 
Comments
Richard Deeming 18-Apr-16 14:15pm    
Based on the previous copy of this question, I suspect the OP is asking the wrong thing. It feels like the issue is more likely a missing if (!IsPostBack) around some data-binding code, and the OP has wandered off down a blind alley trying to solve it in Javascript.

Of course, without seeing the code, I'm just guessing. :)
Sergey Alexandrovich Kryukov 18-Apr-16 14:26pm    
Maybe. Anyway, I still think that knowing the alternative approach I used and suggest can be useful in many cases, because it can work in very many different situations, not only when postback check is missing, but even when there is nowhere to post to. :-)
—SA
Richard Deeming 18-Apr-16 14:59pm    
Don't post large blocks of code in the comments. Click "Improve question" and add them to your question instead.

Also, you still haven't shown the code that binds the grid, or how that code is called.
Kishor-KW 18-Apr-16 15:06pm    
yes sorry for that..will take care next time. thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900