Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have one textbox which is disable first and two buttons one is Edit and other is Done which is invisible at start

In textbox I already have some text when I click on Edit button then Textbox get enable and Done button is visible. So I change the text of Textbox and click on Done button

which contain following code

string suggtxt = textbox.Text;

but it contain null. why? Is there changes are not reflected or chages will reflect after some event? if yes then Click on Done button is also a one event.

what should i do to get textbox edited value

my code is:

C#
protected void btnDone_Command(object sender, CommandEventArgs e)
{
int index = 0;
string suggtxt = "";
if (int.TryParse(e.CommandArgument.ToString(), out index))
{
TextBox txt = (TextBox)GridViewUserScraps.Rows[index].FindControl("suggText");


suggtxt = txt.Text;




}
}

it is a webform application


What I have tried:

I have one textbox which is disable first and two buttons one is Edit and other is Done which is invisible at start

In textbox I already have some text when I click on Edit button then Textbox get enable and Done button is visible. So I change the text of Textbox and click on Done button

which contain following code

string suggtxt = textbox.Text;

but it contain null. why?
Is there changes are not reflected or chages will reflect after some event? if yes then Click on Done button is also a one event.

what should i do to get textbox edited value
Posted
Updated 12-Apr-16 23:28pm
v2
Comments
Rishikesh_Singh 13-Apr-16 1:30am    
Is it winform application or web application. Please add the code otherwise it's difficult to find the issue.
Kishor-KW 13-Apr-16 1:32am    
protected void btnDone_Command(object sender, CommandEventArgs e)
{
int index = 0;
string suggtxt = "";
if (int.TryParse(e.CommandArgument.ToString(), out index))
{
TextBox txt = (TextBox)GridViewUserScraps.Rows[index].FindControl("suggText");


suggtxt = txt.Text;




}
}

it is a webform application
an0ther1 13-Apr-16 1:46am    
I would suggest you use your debugger.
You will likely find that the TextBox control is not being set via FindControl.
If you have a reference to a Textbox it cannot be NULL.

Kind Regards
Kishor-KW 13-Apr-16 1:54am    
ok, but changes should have to reflect, but its not. new text type into the textbox is not come into the suggtxt string. why?

"which contain following code
C#
string suggtxt = textbox.Text;

but it contain null. why?"

Well...it doesn't. The Text property never returns null - it can return an empty string, but not null
What's happening is that the fault is in the earlier code:
C#
TextBox txt = (TextBox)GridViewUserScraps.Rows[index].FindControl("suggText");
For some reason, that is returning null - which means that FindControl cannot find any control with that name.
This could be because you spelled it wrong, the index is wrong (possibly because the CommandArgument string is wrong) or almost anything else!
And the problem is that we can't tell, because it takes the whole of your code to get to that point.
So...start with the debugger. put a breakpoint on the first line of the method, and start looking at exactly what is going on. Look at what is in variables. Think about what they should be. Examine the content of your GridViewRow. It should be reasonably obvious with a bit of close inspection.

But we can't do any of that for you - we can't run your whole code, and that fragment is useless in isolation because it relies on the rest of your code and data to set everything up!
 
Share this answer
 
Comments
Kishor-KW 13-Apr-16 2:02am    
yes I did this. it returns a old value which textbox already contain. (it does not return null my textbox was empty sorry for that). but when I change the contain of textbox and click on Done, new value in textbox which is edited should have to come in suggtxt string. but its not. Previous textbox value is remain there.
OriginalGriff 13-Apr-16 2:44am    
What environment? WinForms? Web?
Kishor-KW 13-Apr-16 4:25am    
its an webform application
OriginalGriff 13-Apr-16 4:37am    
So start with Page_Load: are you doing anything to the Gridview in that?
Kishor-KW 13-Apr-16 4:27am    
simply said i want functionality like Comments we post comments then able to edit original one,like we do here
Hey. I think you need to commit your gridview changes. Please try to use below code

C#
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}
 
Share this answer
 

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