views:

84

answers:

1
+1  Q: 

Callback function?

I need to callback Javascript function in my code, but not firing. I am providing details what I am doing?.

  1. I have input button in the page that calling javascript function. There I am loading another ProfilePic.aspx page. ProfilePic.aspx has FileUpload, OK and cancle button

    <input type=button value="Change Image" onclick="javascript:SelectUserImage()" />
    
  2. Javascript functions are

    <script type="text/javascript">
    function SelectUserImageCallback(ret) {
        var imgId = 'ctl00_PlaceHolderMain_prof_imgUser';
        var clearId = 'ctl00_PlaceHolderMain_prof_hidImageURL';
        if (ret) {
            if (ret == '__RESET__') {
                document.getElementById(imgId).src = '\u002f_layouts\u002fimages\u002fno_pic.gif';
                document.getElementById('ctl00_PlaceHolderMain_prof_hidImageURL').value = '';
                document.getElementById(clearId).style.display = 'none';
            }
            else {
                document.getElementById(imgId).onload = 'imgResizeMax(\'ctl00_PlaceHolderMain_prof_imgUser\', 100);imgResizeTbl(\'ctl00_PlaceHolderMain_prof_imgUser\');';
                document.getElementById(imgId).src = ret;
                document.getElementById('ctl00_PlaceHolderMain_prof_hidImageURL').value = ret;
                setTimeout('imgResizeMax(\'ctl00_PlaceHolderMain_prof_imgUser\', 100);imgResizeTbl(\'ctl00_PlaceHolderMain_prof_imgUser\');', 1);
                setTimeout('imgResizeMax(\'ctl00_PlaceHolderMain_prof_imgUser\', 100);imgResizeTbl(\'ctl00_PlaceHolderMain_prof_imgUser\');', 100);
                document.getElementById(clearId).style.display = '';
            }
        }
    }
    function SelectUserImage() {
        var href = '\u002f_layouts\u002fProfilePic.aspx';
    
    
    
    var features = 'resizable: yes; status: no; scroll: no; help: no; center: yes; dialogWidth: 460px; dialogHeight: 140px; width:460;height:240;menubar:no;directories:no;location:no;';
    commonShowModalDialog(href, features, SelectUserImageCallback, null);
    
    }

  3. In the ProfilePic.aspx page once user click OK buttong. I am upload his pic with some logic then I am closing window with javascript

protected void btnOK_Click(Object sender, EventArgs e) {

    try
    {
       // My logic Here

       Debug.WriteLine("Shared Pictures Save Ends: " + DateTime.Now);
       Response.Write ("<script language =javascript>close();</script>");
       Response.End();
    }
    catch (Exception exception)
    {

        LogMessage(exception.Message, EventLogEntryType.Error);
        if (exception.Message.ToLower().Contains("blocked"))
            errorDisplay.Text = "* This type of file has been blocked by the  administrator, please try a different file.";
        else
        {
            errorDisplay.Text = exception.Message;
        }
    }
}

My Question: I am able to close the window but, What ever I need to call callback function `SelectUserImageCallback' not firing. I need to call this method after OK button part execution done.

A: 

Are you closing the window before the callback executes? I've done that before. As an experiment, try commenting out the code that closes the window.

You may have to restructure your code so that the callback function closes the window when it's finished whatever it's doing.

Update: Sorry, I misunderstood the question. There was a lot of code and I didn't read it all. I thought the call back was in the dialog page, but it looks like it's in the main page. I'm not familiar with commonShowModalDialog(), but it looks like it may have something to do with SharePoint. Do you have any documentation on that method? I found this discussion that makes it look like there's a special way to return a value from the dialog box. It may be that your callback isn't being called because you're not closing the window the right way. (That's a total guess on my part.)

Good luck.

Don Kirkby
If comment code that closed window. How my window will close autometically and call callback function?
James123
Sorry, @James123, I misunderstood. I've updated my answer with some guesses.
Don Kirkby
Is there any other without using commonShowModalDialog(). and use regular asp.net dialog that open another aspx page and retrun value.
James123
Is jQuery an option, @James123? This answer discusses how to use jQuery's dialog feature: http://stackoverflow.com/q/366696/4794#416900
Don Kirkby