Thanks for your answer. Is this working in all browsers? I will try this someday but now I'm doing the insert with AJAX. It's much easier although some say that AJAX isn't so good performance-wise.
Thanks!
all the best
Please mark as answer if the post(s) help you. In that way the others will much easily find the solutions for their problems.
Ok. I just wanted to say that I decided to do this with AJAX modal popup extender. I will try your 2 solutions, I hope soon and see if they work in my application.
Thank you for your time and help!
Please mark as answer if the post(s) help you. In that way the others will much easily find the solutions for their problems.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: using JQuery modal popup for inserting data into SQL Server table
Dec 22, 2009 10:23 PM|LINK
There are only 2 ways to move client-side values to server-side code -- Use AJAX or execute a PostBack.
Ajax :
//////////////////////////////////////////////////////////////////////////
// Page1.aspx
//////////////////////////////////////////////////////////////////////////
<script type="text/javascript">
<!--
callAjax = function (webUrl, queryString)
{
var xmlHttpObject = null;
try
{
// Firefox, Opera 8.0+, Safari...
xmlHttpObject = new XMLHttpRequest();
}
catch(ex)
{
// Internet Explorer...
try
{
xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(ex)
{
xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
}
}
if ( xmlHttpObject == null )
{
window.alert('AJAX is not available in this browser');
return;
}
xmlHttpObject.open("GET", webUrl + queryString, false);
xmlHttpObject.send();
var valueSent = xmlHttpObject.responseText;
return valueSent;
}
// -->
</script>
<script type="text/javascript">
<!--
function doUpdate()
{
var webUrl = 'AjaxPage.aspx';
// Add any additional values needed for the update to the QueryString...
var queryString = '?CallRequest=UpdateDatabase&DbKey=1234';
var returnCode = callAjax(webUrl, queryString);
alert('returnCode: ' + returnCode);
}
// -->
</script>
//////////////////////////////////////////////////////////////////////////
// AjaxPage.aspx.cs
//////////////////////////////////////////////////////////////////////////
protected string UpdateDatabase(string dbKey)
{
string returnValue = "OK";
// Update the database here setting the returnValue variable to "Failed" if not successful...
return returnValue;
}
private void Page_Load(object sender, System.EventArgs e)
{
string callRequest = (this.Request["CallRequest"] == null) ? string.Empty : this.Request["CallRequest"];
string returnValue = string.Empty;
if ( callRequest == "UpdateDatabase" )
{
string dbKey = (this.Request["DbKey"] == null) ? string.Empty : this.Request["DbKey"];
returnValue = UpdateDatabase(dbKey);
}
this.Response.ClearHeaders();
this.Response.Clear();
this.Response.Write(returnValue);
this.Response.End();
}
PostBack:
<script type="text/javascript">
<!--
function doUpdate()
{
__doPostBack('UpdateDatabase', '1234');
}
// -->
</script>
private void Page_Load(object sender, System.EventArgs e)
{
// Insure that the __doPostBack() JavaScript method is created...
ClientScript.GetPostBackEventReference(this, string.Empty);
if ( this.IsPostBack )
{
string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];
if ( eventTarget == "UpdateDatabase" )
{
UpdateDatabase(eventArgument);
}
}
}
NC...
StarkWolf
Member
308 Points
217 Posts
Re: using JQuery modal popup for inserting data into SQL Server table
Dec 28, 2009 03:38 PM|LINK
Hello!
Thanks for your answer. Is this working in all browsers? I will try this someday but now I'm doing the insert with AJAX. It's much easier although some say that AJAX isn't so good performance-wise.
Thanks!
all the best
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: using JQuery modal popup for inserting data into SQL Server table
Dec 28, 2009 04:51 PM|LINK
Not sure who you are directing the question to, since I gave you an AJAX solution also. My 2 solutions should work in all browsers however.
NC...
StarkWolf
Member
308 Points
217 Posts
Re: using JQuery modal popup for inserting data into SQL Server table
Dec 30, 2009 09:49 AM|LINK
Ok. I just wanted to say that I decided to do this with AJAX modal popup extender. I will try your 2 solutions, I hope soon and see if they work in my application.
Thank you for your time and help!