0

I have a very strange issue which I just don't understand. I have an asp.net repeater control which is built into a jquery modal.

The code for the control is here.

<div id="dialog" style="display:none">
<asp:Repeater id="myrepeater" runat="server" >
    <HeaderTemplate></HeaderTemplate>
    <ItemTemplate>
        <asp:TextBox ID="txtAnswer" TextMode="MultiLine" Columns="50" Rows="4" runat="server" />

    </ItemTemplate>
    <FooterTemplate></FooterTemplate>
</asp:Repeater>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" style = "display:none" OnClick="Submit1" OnClientClick="return ValidateInput()" />

I then call jquery/javascript PopupCenter from asp.net vb.net code behind method.

function PopupCenter() {
    $(function () {
        $("#dialog").dialog({
            title: "Questions and answers",
            width: 1200,
            height: 750,
            buttons: {
                Ok: function () {
                    $("[id*=Button1]").click();
                },
                Close: function () {
                    $(this).dialog('close');
                }
            }
        });
    });
}

Everything works well. the modal appears with the textboxes. I have bound my asp.net button to a postback event called Submit1. Inside the code behind which successfully fires I then do this...

Protected Sub Submit1(ByVal sender As Object, ByVal e As System.EventArgs)
 For i = 0 To myrepeater.Items.Count - 1
    Dim dynTxtAnswer As TextBox =    DirectCast(qtaRepeater.Items(i).FindControl("txtAnswer"), TextBox)           
Next
End Sub

So in above for loop what I am expecting is the Text values for the textboxes in the repeater. I can get access to the textboxes. Just it states an empty string and not the string values. So overall completely stumped. I wondered if anyone had an idea of why this is happening.

Thank you.

Humayun Shabbir
  • 2,961
  • 4
  • 20
  • 33
user3036965
  • 155
  • 2
  • 18
  • add `appendTo: "form"` property in your `$("#dialog").dialog({` method – joker Aug 01 '14 at 08:43
  • Could you be more descriptive. Thanks for advice so far. – user3036965 Aug 01 '14 at 08:50
  • appendTo is a property for dialog function its still not work then referr que http://stackoverflow.com/q/757232/3087450 it may be useful for u – joker Aug 01 '14 at 08:59
  • The thing is I can raise a postback. i can even get hold of the textboxes and loop through them within the code behind event. So postback is done. I just cannot obtain the values. – user3036965 Aug 01 '14 at 09:15

3 Answers3

0

Try it below code

Add code in OK Event of modal dialog

Ok: function () 
{
   __doPostBack("<%= Button1.UniqueID %>", "");
}
0

Please try this code :

Dim textString as String = "Null"  

Dim txtBoxValue As TextBox    

Dim i As Integer = 0   

For Each item In myrepeater.Items 

   txtBoxValue = item.FindControl("txtAnswer")  

   If Not IsNothing(txtBoxValue) Then    

     i += 1  

     textString = txtBoxValue.Text 

   Else        
   End If    
Next

Let me know is it works for you or not.

  • Hi, I tried your approach which is similar to what I am doing. it didn't work. I can get into the loop, so it picks up the controls, much like my one. It just doesn't see any text propety values. – user3036965 Aug 01 '14 at 14:01
0

I couldn't resolve the issue so I managed to do a workaround.

I created a hidden asp.net field

 <input id="Hidden1" type="hidden" runat="server" />

Then I picked up the repeater textboxes using Jquery and bundled the values into a javascript array, seperated it using | like this...

  var cntrlAnswer = $('.cssAnswer')
  for (var i = 0; i < cntrlAnswer.length; i++) {
            repeaterTxtVals[i] = cntrlAnswer[i].value}

  document.getElementById('<%= Hidden1.ClientID %>').value = repeaterTxtVals.join('|');   

Then in the codebehind event handler I picked it up and did stuff with it.

  Dim strAnswers As String() = Hidden1.Value.Split("|".ToCharArray())

Thanks for any tips I have been given, they helped alot.

user3036965
  • 155
  • 2
  • 18