Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am entering the value into the text box. on button ID is btnDone I want to store textbox value into the string variable str. but when i click on button then textbox value is vanished as because of postback. please help me to how to get the textbox value into the string when I click on button.

My button button and textbox both are in GridviewControl
Posted
Updated 18-Apr-16 7:59am
v3
Comments
Kishor-KW 18-Apr-16 6:22am    
plz some one give a javascript to get textbox value even after postback occured
Kishor-KW 18-Apr-16 12:16pm    
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.. or should i have to ask new question?
Richard Deeming 18-Apr-16 13:33pm    
The most likely cause is that you're binding the grid every time the page loads, and you've forgotten to wrap that code in an if (!IsPostBack){ ... } block.

But since we can't see your code, there's no way to be sure, and no way for anyone to help you.

Please see my recent solution: http://www.codeproject.com/Answers/1094229/How-to-maintain-same-textbox-value-after-postback#answer1[^].

Please don't re-post; this is considered as abuse, by obvious reasons.

—SA
 
Share this answer
 
Rather than taking onlick event, Try OnRowCommand event for button of Gridview.
 
Share this answer
 
v2
Comments
Kishor-KW 18-Apr-16 1:56am    
its not executing OnRowCommand event,means after click on button it not goes onOnRowCommand at code behind
Member 12003400 19-Apr-16 9:08am    
Have you declared that event in GridView?

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