I have a click event on a button that opens a sp ui modal dialog page. and returns a specific value from a text area on that page. I was able to open the page in the modal dialog and able to return the values from the text area back to the parent page, but my issue is I was not able to pass these values back to the code behind. I tried to use the hidden field. It seems to be working but the problem is upon first click event of the button, the values are not returned and when I tried to debug it, the whole event is being executed first so the values are always empty on first click.
Is there another way that I can pass the values back to the code behind?
Here is the code behind of the button:
protected void btn_Click(object sender, EventArgs e)
{
//popup modal window for comment is loaded.
ClientScriptManager cs = Page.ClientScript;
StringBuilder scriptToExecute = new StringBuilder();
scriptToExecute.Append("ExecuteOrDelayUntilScriptLoaded(OpenCommentForm,'sp.js');");
cs.RegisterStartupScript(this.GetType(), "PopUpCommentScript", scriptToExecute.ToString(), true);
string hiddenField1Val = HiddenField1.Value.ToString();
string hiddenField2Val = HiddenField2.Value.ToString();
}
Here is the js:
function OpenCommentForm() {
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = "/_layouts/commentform.aspx"; // URL of the Page
dialogOptions.width = 600; // Width of the Dialog
dialogOptions.height = 400; // Height of the Dialog
dialogOptions.title = "Comment Form";
dialogOptions.args = null;
dialogOptions.allowMaximize = false;
dialogOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback); // Function to capture dialog closed event
SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
}
function CloseCallback(strReturnValue, comment) {
if (strReturnValue == 1) // Perform action on Ok.
{
var hiddenResult = $("[id$='ctl00_PlaceHolderMain_HiddenField1']").val(strReturnValue);
var hiddenComment = $("[id$='ctl00_PlaceHolderMain_HiddenField2']").val(comment);
}
}
Thank you very much for the help in advance.