Search code examples
asp.netlistviewmodalpopup

How to fill a TextBox in InsertItemTemplate(ListView) with a selected Value from ModalPopup displayed by clicking a Link in the InsertItemTemplate?


I have really put in significant efforts to somehow find an answer; having failed I have then searched many forums before coming to bother the experts here. Please help!

I have a Listview in a USerControl of my main form; its InsertItemTemplate has a TextBox whose value is to be filled in by Clicking a Linkbutton in a Row of another Listview (in another UserControl) in the ModalPopUp Panel, which Pops up when a Linkbutton in the Parent UserControl is Clicked. After the selection (by clicking the LinkButton in the ModalPopUp), the ModalPopup closes immediately and in Code-Behind of the Child-UserControl, I save the Selected-Value in a Session variable. My problem is (Because the InsertItemTemplate is already remaining displayed) I do not know where to put the code for filling the TextBox (in the Parent UserControl) with the saved value from the Session-Variable.

ItemCreated, ItemDataBound are already executed before the ModalPopUp is displayed. So, though I have the required Value of the TextBox in the Session-Variable, I am unable to fill the TextBox in the InsertItemTemplate.

I will appreciate any suggestions, if any of you have found any answers to such a situation. I feel SOMEHOW the InsertItemTemplate should be made to load again and this TextBox in it should be filled in the ItemCreated for the InserItem datatype. But I do not know how to make it happen???

Any thoughts welcome. I have similar logic in many places in my App; and if I can't do it it will significantly affect my app :-(.

Hope one of you experts will kindly help me out. Thanks.


Solution

  • Thanks. I could fix it. Mentioning it here for some newbie (like me) who may face a similar issue.

    The question was, where to put the Code (for the Selected Value to fill the TextBox in the InsertItemTemplate) in the scenario described above in the question.

    I find that in the Pre-Render Event of the Parent UserControl, in the PostBack mode, after finding the said TextBox Control via the e.InsertItem.FindControl("TextBox"), I am able to fill it with the selected value. I don't know if this is the best way to do it, but it works fine now.

    Hope this may be of some help to someone! Thanks.