Alex Rivera | Logout

modalpopupextender and commas appearing in my textbox asp.net

Asked 2009-10-19T10:50:41.317
12

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?

Edit
Report

3 Answers

3

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.

answered 2010-07-01T06:14:25.097
3

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.

answered 2011-01-14T17:58:51.933
2

My answer was similar to Smarty's. My page looked like this...

<UpdatePanel>
    <GridView>
        <Button> <-- These buttons fire modal popup programmatically.
        <Button>
        <Button>
    </GridView>
    <ModalPopup>
    <HiddenField> <-- Dummy target of modal popup.
</UpdatePanel>

The fix was to change it to this...

<UpdatePanel>
    <GridView>
        <Button> <-- These buttons fire modal popup programmatically.
        <Button>
        <Button>
    </GridView>
</UpdatePanel>
<ModalPopup>
<HiddenField> <-- Dummy target of modal popup.

I had to register each button as a postback control with the scriptmanager on the gridview rowdatabound event. The down side is that I have more full postbacks. But, it solved the problem.

answered 2010-09-14T01:26:14.947

Your Answer