1

This will not be a very clear explanation of my problem, but I don't know how to explain it better.

I have a gridview which I create dynamically on PreInit. This gridview has textboxes dynamically added on each row.

Everytime I push the button, I loop inside the gridview cells and get the Text of the textboxes -and update the database.

the first time the gridview is created, row uniqueID's are like this: ctl03, ctl04, ctl05, ctl06 (thus, the textbox ID's are ctl03$txt0 etc..)

The first time I push the button, the row UniqueID's are still the same, so that I can find the controls by FindControl(ID) method, or using Request.Form[txt.UniqueID]

However; after the first time, whenever I push the button, the row ClientId's are created like the following: ctl02, ctl03, ctl04, ctl05.. So that I cannot find the Textboxes and cannot catch the Text written on them.

When I look at the rendered HTML code, I see that the rowClientID's are still the same with the first created ones (ctl03, ctl04, ctl05, ctl06)

Does anyone have any idea why the rowIDs (naming container IDs) change after the first update?

Thanks in advance.

louip
  • 11
  • 2

1 Answers1

0

One solution is to create your textboxes with static ids and not let it dynamic create by asp.net. This can be done if you use asp.net ver 4.

Other solution is to just render a simple <input name="KnowName01" id="KnowId01" type="text" value="your value here" maxlength="100" etc... >

and then on post back you just capture the return with the old way and get the value.

Request.Form["KnowName01"]

At the end, the TextBox is nothing more than a render of the input, plus some checks for what write on it, including Anti-XSS safe.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Correct me if i'm wrong but isnt it the UniqueID that we are sending to Request.Form as the key? I assign ID's to textboxes (say txt0) but when rendered, asp.net puts prefixes which makes my initial Id sth like 'ctl00$CntntPlcHld$ctl02$txt0'. The problem occurs here: I get the initial rowID=ctl03 But after pressing the button for the second-or third- update, rowID becomes ctl02. The interesting part is that it's still ctl03 on the html code. And since the two rowID's on codebehind and on HTML rendered code does not match, I get a wrong UniqueID for textbox and cannot catch the Text on it. – louip Jun 28 '11 at 12:49
  • @louip yes the uniqueid is the one on the form, this is the Name on the rendered tag. – Aristos Jun 28 '11 at 13:01