I am currently using jQuery UI dialog to show a dialog box with a form after a user clicks a link. I have correctly populated the jquery UI dialog with the appropriate aspx page. I am having trouble knowing how to submit the form loaded into the dialog when the save button is clicked. Right now I am calling the button click event on the loaded form, that does save the data, but then it posts back to the same page that is loaded in the dialog, but on its own page. What I want is to save the data in the dialog, then refresh the current aspx page the original link to open the jquery dialog box was on.
So to summarize, I need to figure out a way when the save button is clicked on the jquery dialog, I am able to call the click handler in my code behind, do not return a response from that call, and then close the dialog, and postback to the parent page.
Javascript for creating and opening dialog:
$(document).ready(function () {
$("#dialog").dialog({
autoOpen: false,
modal: true,
resizable: false,
title: "Item Edit",
buttons: {
"Save": function (e) {
$('input#<%=btnSave.ClientID %>').click();
}
}
});
$(".item").on("click", function () {
var itemId = $(this).attr("itemId");
var url = window.location.protocol + "//" +
window.location.host + "/ItemEdit.aspx?itemId=" + itemId;
$("#dialog").load(url);
$("#dialog").dialog("open");
return false;
});
});
Form loaded into jquery dialog:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="ItemEdit.aspx.vb"
Inherits="ItemEdit" %>
Item Edit
Item:
/>
tabindex="-1" style="position:absolute; top:-1000px"/>
Code behind for page loaded into jquery dialog: Imports System.Data.OleDb Imports System.IO Imports System.Data.SqlClient
Partial Public Class ItemEdit
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
If (Not Page.IsPostBack) Then
If Request.QueryString("itemId") IsNot Nothing Then
Dim itemId As String = Request.QueryString("itemId")
Dim command As New OleDbCommand("SELECT * FROM items WHERE id =
" & itemId, New OleDbConnection(ConnectionString))
Try
command.Connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
If reader.Read() Then
lblItem.Text = reader("item")
cbxMB.Checked = reader("mb")
cbxPP.Checked = reader("pp")
cbxB.Checked = reader("b")
cbxT.Checked = reader("t")
lblItemId.Text = reader("itemId")
End If
reader.Close()
Finally
command.Connection.Close()
End Try
End If
End If
End Sub
Protected Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim command As New OleDbCommand("UPDATE items SET b=" &
Math.Abs(CInt(cbxB.Checked)) & ",t=" & Math.Abs(CInt(cbxT.Checked)) & ",mb="
& Math.Abs(CInt(cbxMB.Checked)) & ",pp=" & Math.Abs(CInt(cbxPP.Checked)) & "
WHERE id=" & lblItemId.Text, New OleDbConnection(ConnectionString))
Try
command.Connection.Open()
command.ExecuteNonQuery()
Finally
command.Connection.Close()
End Try
End Sub
End Class