modalpopupextender and commas appearing in my textbox asp.net

后端 未结 15 472
失恋的感觉
失恋的感觉 2020-12-24 05:07

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 ModalPopupExtende

相关标签:
15条回答
  • 2020-12-24 05:45

    I had a similar problem, having a jQuery Dialog inside an UpdatePanel. As I could read on different sites, the problem is caused by duplicates inside the DOM tree.

    In the end I found a very simple solution. I assign the dialog to the div, then open or close it by JavaScript and then run this little peace of code to remove the duplicates:

    var count = $(".dialog").length;
    for (i = 1; i < count; i++) {
        $(".dialog").first().remove();
    }
    

    EDIT: it turned out not to be SO simple. In the end, my code looked like this:

    In document ready (and also asynchronous page calls):

    function AddDialog() {
    
        var dlg = $(".dialog").dialog({ autoOpen: false });
        dlg.parent().appendTo($("form:first"));
    
        var targetSelector = ".myDialog"; // watch out: can't use ID here!
    
        if (mustOpenDialog) {
    
            $(targetSelector).last().remove();  //-- remove last copy
    
            var dlg = $(targetSelector).dialog({ autoOpen: true });
    
            var count = $(targetSelector).length;
            for (i = 1; i < count; i++) {
                $(targetSelector).last().remove();
            }
        }
    
        if (mustCloseDialog) {
    
            $(targetSelector).dialog("close");
            var count = $(targetSelector).length;
            for (i = 1; i < count; i++) {
                $(targetSelector).first().remove();
            }
        }
    
    }
    

    In my complete code, mustOpenDialog and mustCloseDialog are set in codebehind.

    0 讨论(0)
  • 2020-12-24 05:46

    Just sharing this solution to everyone on this problem. Try not to use asp control instead use html.

    *<input type="text" id="txtID" runat="server" class="myClass" />*
    

    this works fine for me.

    Thanks,

    0 讨论(0)
  • 2020-12-24 05:49

    Same here. No clue for why it happens. Every postback initiated by buttons within the panel adds commas and previous values to all text fields.

    Hooking into TextBox.Text setter revealed that the corrupted data comes from postdata collection. So it means that just before postback the ModalPopupExtender corrupts the data.

    P.S. I'm not using UpdatePanel, but regular Panel so there are no triggers associated with buttons.

    Updated: Solution found.

    The problem seems to go away when rolling back to May's release of AjaxToolKit (http://ajaxcontroltoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27326).

    0 讨论(0)
  • 2020-12-24 05:49

    I had this issue and lost quite a bit of time on it and found that it was caused by an extra tag hiding out that I forgot to remove when changing markup.

    Make sure on the .aspx page all tags line up correctly.

    <div>
       **Lots of code here**
       </div> <-- That guy owes me a vacation!
    </div>
    
    0 讨论(0)
  • 2020-12-24 05:51

    I also found a forum indicating that it may be standard html behaviour for when there are multiple controls on the form with the same name. This in mind (and assuming there is a bug in the ajax controls) The way I coded around it was to add in my Page_Load the following kind of statement for each of my textboxes.

    string[] vals = txtValue.Text.Split(Convert.ToChar(",")); txtValue.Text = vals[vals.Length - 1];//It appears my latest value was always in the last item

    Since the form load happens before the button event I sort out my fields before they get to the event that deals with their values.

    0 讨论(0)
  • 2020-12-24 05:53

    I have successfully implemented a complete hack based on Jen's response. I use an asp:HiddenField to hold the value I want to post back, and I populate it with a pure HTML input box

    <asp:HiddenField ID="txt" runat="server"/>
    <input type="text" onchange='document.getElementById("<%= txt.ClientID %>").value = this.value;' />
    

    This is lighter weight than Jen's solution as you're still only posting back one server control.

    BTW, this is a very significant bug in the Ajax Toolkit. You can vote and comment on it here:

    CodePlex Issue

    Pretend you're in Chicago. Vote early, vote often.

    0 讨论(0)
提交回复
热议问题