|
-
May 15th, 2008, 07:49 PM
#1
Thread Starter
Frenzied Member
[2005] refresh asp component only, not the whole page...
Is there a way to make it to were when I click a button that
inserts into a database, and then I refresh a datagrid, that the
page doesn't reload, only the datagrid?
Am I going to have to use AJAX?
Thanks,
Justin Fox
-
May 15th, 2008, 07:51 PM
#2
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
And If I have to use AJAX, how do I modify asp stuff through javascript? or can I?
Thanks,
Justin Fox
-
May 16th, 2008, 01:56 PM
#3
Re: [2005] refresh asp component only, not the whole page...
Yes, place your gridview (use the gridview, it's a better version of the datagrid) in an UpdatePanel.
For more information on Ajax, look at the sticky thread at the top of this forum for AJAX tutorials.
-
May 19th, 2008, 08:55 AM
#4
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
Ok, in the tutorial, I see that is shows you how to do this step by step
using wizards and such. I'm going to have a combobox with items, and everytime I change the index, update the gridview to the data corresponding to that item selected.
How can you do this stuff programming wise. I know you can associate a gridview with a storedprocedure, but my stored procedure is going to have different parameters each time.
Thanks,
Justin Fox
-
May 19th, 2008, 08:58 AM
#5
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
Also, I don't have the AJAX enabled website template installed. How do I get it?
Thanks,
Justin
-
May 19th, 2008, 10:02 AM
#6
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
So, you can write a javascript ajax function in the html, and just do like so in the page_load;
asp Code:
myaspbutton.attributes.add("onClick","return myAjaxFcn();");
now, usually when I use ajax, I use php to return any data that I need,
and if it's anything other that plain text, I use the eval() function.
If I did the same thing, but instead just use an aspx page to access
the database and such, how would I refresh the gridview? If it is in
an updatePanel, will it update automatically if I do:
asp Code:
myGridView.dataSource = newDS;
will that work?
Another thing is, can I update a gridView on one .aspx page from another's page_load function?
Thanks,
Justin Fox
-
May 19th, 2008, 12:37 PM
#7
Re: [2005] refresh asp component only, not the whole page...
Your best bet (for better examples) is to look at the quickstart samples. This one, for example has a Gridview in an UpdatePanel. Add a dropdownlist as well, handle the dropdownlist's event, reset the gridview's data source.
UpdatePanel overview - http://www.asp.net/AJAX/Documentatio...lOverview.aspx
-
May 19th, 2008, 12:40 PM
#8
Re: [2005] refresh asp component only, not the whole page...
Follow these instructions to download and install and to get ASP.NET AJAX to work with VS 2005 (or you could just get VS 2008 if you can)
http://www.asp.net/AJAX/Documentatio...SPNETAJAX.aspx
Refreshing the gridview is a matter of simply reassigning the datasource and calling the .databind() method again.
Code:
Another thing is, can I update a gridView on one .aspx page from another's page_load function?
That question doesn't make sense because in a web application, only one page is visible at a time. Pages cannot affect each other, they can only send information to each other.
-
May 19th, 2008, 01:05 PM
#9
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
What I'm really wanting to know is, can I use AJAX in a web application without using the ASP.NET AJAX tools and extensions?
Like incoporating this basic AJAX structure into a web app.
HTML Code:
<script type = "text/javascript">
var xmlHttp;
function emailTo(user,useremail,usersubject,usermessage)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="default.aspx";
url=url+"?name="+user+"&useremail="+useremail+"&subject="+usersubject+"&Umessage="+usermessage;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
Thanks,
Justin Fox
-
May 19th, 2008, 01:09 PM
#10
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
but instead of just alerting the responsetext.
have the response be a custom object?
Justin Fox
-
May 19th, 2008, 01:12 PM
#11
Re: [2005] refresh asp component only, not the whole page...
 Originally Posted by MonkOFox
What I'm really wanting to know is, can I use AJAX in a web application without using the ASP.NET AJAX tools and extensions?
Like incoporating this basic AJAX structure into a web app.
HTML Code:
<script type = "text/javascript">
var xmlHttp;
function emailTo(user,useremail,usersubject,usermessage)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="default.aspx";
url=url+"?name="+user+"&useremail="+useremail+"&subject="+usersubject+"&Umessage="+usermessage;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
alert(xmlHttp.responseText);
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
Thanks,
Justin Fox
To answer that specific question, yes, of course you can. ASP.NET AJAX is just a framework written over the kinds of things you're doing. Just put it into your <script> tag at the top of the page.
-
May 19th, 2008, 01:13 PM
#12
Re: [2005] refresh asp component only, not the whole page...
 Originally Posted by MonkOFox
but instead of just alerting the responsetext.
have the response be a custom object?
Justin Fox
What do you mean by custom object? You can get it to write to an element on the page.
Code:
document.getElementById('txtBoxID1').value = "You don't have javascript, OMG!";
-
May 19th, 2008, 01:24 PM
#13
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
Ok, so with an updatepanel, if you call updatepanel.update or whatever, after you assign the gridviews datasource to the newly updated DS, then it will update only that panel all by itself?
if that is the case, couldn't I just have the dropdown onchange event just set the new parameter and update the dataset and then assign it without ever using AJAX?
Thanks A lot,
Justin Fox
-
May 19th, 2008, 01:25 PM
#14
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
And by custom object, I was meaning like a DataSet or a Class that has a Dataset as one of its members.
Justin
-
May 19th, 2008, 01:33 PM
#15
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
nevermind, updatepanel comes with the AJAX stuff for .NET...
I was confused obviously
sorry,
Justin
-
May 19th, 2008, 01:45 PM
#16
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
Ok, so say I wanted to use my own AJAX template.
I don't see how I can update a <asp:gridview> from Javascript.
because If I call an .aspx page and return a DataSet somehow( which I don't know how). how do I Update the gridview?
or will I have to use a <table></table> and just echo the rows in a while loop?
Thanks mendhak,
Justin
-
May 19th, 2008, 02:02 PM
#17
Re: [2005] refresh asp component only, not the whole page...
You can't make a client side script talk to a server side object. In other words, you can't make javascript manipulate a dataset. This is why AJAX is used - it calls a web page which performs certain data manipulation (such as getting a new dataset) which is then given to a gridview, the 'html source' of which is sent back to the page. That is what the UpdatePanel is all about. It is a specific area in which you perform your javascript based DOM calls and manipulation.
I feel you're trying to jump into the deep end here. I really suggest a few ASP.NET AJAX tutorials first so that you have an understanding of how it all works. Then using the GridView with the Updatepanel will become clear to you.
-
May 19th, 2008, 02:51 PM
#18
Thread Starter
Frenzied Member
Re: [2005] refresh asp component only, not the whole page...
I get it now.
so what I'm doing is fine, just longer I guess.
I understand how the updatePanel is supposed to work, I just don't understand how it works.... get it?
because when you send a request to a page using AJAX, all you get is
a response text back, or you can append stuff to the url and do an operation with the given data on the server-side(such as DB insert/delete/update)
So basicly the only way I can generate dynamic "gridViews" is by:
1: sending data to server.
2: getting dataset based on that data recieved and Response.write() an array of arrays containing each cell's value;
3: getting that array on client-side
4: and then using some sort of nested loop to draw out a table with proper-formatting.
That is, if I choose not to use ASP.NET AJAX v1.0 toolkit
Justin Fox
-
May 20th, 2008, 01:24 AM
#19
Re: [2005] refresh asp component only, not the whole page...
If you choose to use ASP.NET AJAX, then the process is
Send data to server
Web service/page processes data
Return HTML
Receive data from server
Write it out to the updatepanel area, replacing everything in there. (That's how the UpdatePanel works, or at least that's the overview, it may have exceptions)
If you choose not to use ASP.NET AJAX - that is, if you choose to use regular XmlHttpRequest or AJAX, it'll be as you've described, but a much longer process.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|