Search code examples
asp.netmodalpopupextender

modalpopupextender and commas appearing in my textbox asp.net


Some weird stuff is happening, I am converting an application that used to use javascript to open another web page in a tiny window for data input to use a ModalPopupExtender.

It seems to work fine, but in the OK event, when I do txtData.Text (the textbox in my modal popup), it comes back with a comma before the data, so if you type "Rabbit", it comes back as ",Rabbit".

Also when I use it multiple times, in another place where I might click to show it, and type "Fish", it starts coming back with stuff like ",Rabbit,,Fish"

I don't know why or how to stop it from doing this... any ideas?


Solution

  • For some reason it doesn't seem to happen if the textbox is set to ReadOnly.

    I'm thinking there could be a workaround by displaying an editable textbox to the user, catching the keystrokes to it, and updating a readonly textbox that is hidden from the user.

    Still a bit messy, but I can't roll back to May's release because there's another bug in that release with the ComboBox that I need to avoid!


    UPDATE:

    As a bit of background, I have a user control (ascx) inside my modal popup because I need to reuse it. The ascx has to handle the user's input itself (the containing page doesn't know what's going on inside the control) so when the user clicks a button I do a callback and process the data. If a successful result is returned to the client callback function then I simulate a click of what the containing page thinks is the "OK" button which is actually invisible to the user.

    I've changed my code to add a hidden, readonly textbox and copy the text from the original textbox into the new one every time the text changes.

        <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
    

    becomes

        <asp:TextBox runat="server" ID="txtName" onchange="document.getElementById(this.id + 'RO').value = this.value"></asp:TextBox>
        <asp:TextBox runat="server" ID="txtNameRO" ReadOnly="true" style="display:none;"></asp:TextBox>
    

    then when passing values back in the callback instead of getting the value of txtName, I use txtNameRO.

    I don't think this will help if you're doing a postback, but you could add a callback before the postback like I have. Hopefully this will help someone anyway!