473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Having trouble with script to reload parent page?

I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.

I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?

I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.

Any help is greatly appreciated.

-Josh Nikle

Oct 21 '06 #1
5 2323
There are a couple ways I generally connect user controls to objects in the
parent page. Other responders may have other options.

1. You can pass the System.Web.UI.Page object from the page to the
controller as a property.
2. You can pass the GridView object from the page to the controller as
a property.

Either of these solutions allow you to update the GridView in the parent
page from within the user control, or:

3. You can create an event in the user control and subscribe to the
event in the parent page. This is a more robust solution, making your user
control more loosely coupled to the page and more usable elsewhere.

The trade off of #3 is that it takes more coding and testing up front. If
you know your user control will only ever be used in this page and in the way
you are using it now, you may want to choose option 1 or 2. If you're not
sure, and we're usually not as sure as we think we are - that's why good OOP
practices exist in the first place - then you may want to choose option 3.

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Josh Nikle" wrote:
I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.

I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?

I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.

Any help is greatly appreciated.

-Josh Nikle

Oct 21 '06 #2
Whoops. I guess I'm brain dead today. In options 1 and 2, replace
"controller" with "control".

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote:
There are a couple ways I generally connect user controls to objects in the
parent page. Other responders may have other options.

1. You can pass the System.Web.UI.Page object from the page to the
controller as a property.
2. You can pass the GridView object from the page to the controller as
a property.

Either of these solutions allow you to update the GridView in the parent
page from within the user control, or:

3. You can create an event in the user control and subscribe to the
event in the parent page. This is a more robust solution, making your user
control more loosely coupled to the page and more usable elsewhere.

The trade off of #3 is that it takes more coding and testing up front. If
you know your user control will only ever be used in this page and in the way
you are using it now, you may want to choose option 1 or 2. If you're not
sure, and we're usually not as sure as we think we are - that's why good OOP
practices exist in the first place - then you may want to choose option 3.

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Josh Nikle" wrote:
I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.

I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?

I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.

Any help is greatly appreciated.

-Josh Nikle
Oct 21 '06 #3
Thanks for the reply. I use the GridView2 control on the pages, so
looks like option 3 is for me. Can you elaborate on that one for me?
Like I said, I'm new to ASP.NET/C#, and I'm not entirely sure what I
should have in the event in the user control or how or when I'd call it
from the parent page.

Josh Nikle
Dale wrote:
Whoops. I guess I'm brain dead today. In options 1 and 2, replace
"controller" with "control".

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote:
There are a couple ways I generally connect user controls to objects in the
parent page. Other responders may have other options.

1. You can pass the System.Web.UI.Page object from the page to the
controller as a property.
2. You can pass the GridView object from the page to the controller as
a property.

Either of these solutions allow you to update the GridView in the parent
page from within the user control, or:

3. You can create an event in the user control and subscribe to the
event in the parent page. This is a more robust solution, making your user
control more loosely coupled to the page and more usable elsewhere.

The trade off of #3 is that it takes more coding and testing up front. If
you know your user control will only ever be used in this page and in the way
you are using it now, you may want to choose option 1 or 2. If you're not
sure, and we're usually not as sure as we think we are - that's why good OOP
practices exist in the first place - then you may want to choose option 3.

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Josh Nikle" wrote:
I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.
>
I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?
>
I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.
>
Any help is greatly appreciated.
>
-Josh Nikle
>
>
Oct 22 '06 #4
can anyone help me out with this?

josh nikle

Josh Nikle wrote:
Thanks for the reply. I use the GridView2 control on the pages, so
looks like option 3 is for me. Can you elaborate on that one for me?
Like I said, I'm new to ASP.NET/C#, and I'm not entirely sure what I
should have in the event in the user control or how or when I'd call it
from the parent page.

Josh Nikle
Dale wrote:
Whoops. I guess I'm brain dead today. In options 1 and 2, replace
"controller" with "control".

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Dale" wrote:
There are a couple ways I generally connect user controls to objects in the
parent page. Other responders may have other options.
>
1. You can pass the System.Web.UI.Page object from the page to the
controller as a property.
2. You can pass the GridView object from the page to the controller as
a property.
>
Either of these solutions allow you to update the GridView in the parent
page from within the user control, or:
>
3. You can create an event in the user control and subscribe to the
event in the parent page. This is a more robust solution, making your user
control more loosely coupled to the page and more usable elsewhere.
>
The trade off of #3 is that it takes more coding and testing up front. If
you know your user control will only ever be used in this page and in the way
you are using it now, you may want to choose option 1 or 2. If you're not
sure, and we're usually not as sure as we think we are - that's why good OOP
practices exist in the first place - then you may want to choose option 3.
>
Dale
>
--
Dale Preston
MCAD C#
MCSE, MCDBA
>
>
"Josh Nikle" wrote:
>
I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.

I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?

I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.

Any help is greatly appreciated.

-Josh Nikle
Oct 24 '06 #5
Josh,

I apologize for not responding earlier - I missed the notification on this
one. I don't know if you solved it yet, but here's my reply, just in case.

Here is a simple example of adding events to a user control. This is from a
user control that consists of a Save button and a Reset button. The page can
subscribe to the events on the control. This code goes in the user control
class:
#region Button Clicked Events
public event System.EventHandler SaveClicked;
public event System.EventHandler ResetClicked;

void btnSave_Click(object sender, System.EventArgs e)
{
if (SaveClicked != null)
{
this.SaveClicked(sender, e);
}
}

private void btnReset_Click(object sender, System.EventArgs e)
{
if (ResetClicked != null)
{
this.ResetClicked(sender, e);
}
}
#endregion

You can modify this by creating your events as type
System.Web.UI.WebControls.GridViewCommandEventHand ler instead of
System.EventHandler. You could then pass back the gridview as the sender
argument and the item as the e argument.

HTH

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA
"Josh Nikle" wrote:
can anyone help me out with this?

josh nikle

Josh Nikle wrote:
Thanks for the reply. I use the GridView2 control on the pages, so
looks like option 3 is for me. Can you elaborate on that one for me?
Like I said, I'm new to ASP.NET/C#, and I'm not entirely sure what I
should have in the event in the user control or how or when I'd call it
from the parent page.

Josh Nikle
Dale wrote:
Whoops. I guess I'm brain dead today. In options 1 and 2, replace
"controller" with "control".
>
Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
>
>
"Dale" wrote:
>
There are a couple ways I generally connect user controls to objects in the
parent page. Other responders may have other options.

1. You can pass the System.Web.UI.Page object from the page to the
controller as a property.
2. You can pass the GridView object from the page to the controller as
a property.

Either of these solutions allow you to update the GridView in the parent
page from within the user control, or:

3. You can create an event in the user control and subscribe to the
event in the parent page. This is a more robust solution, making your user
control more loosely coupled to the page and more usable elsewhere.

The trade off of #3 is that it takes more coding and testing up front. If
you know your user control will only ever be used in this page and in the way
you are using it now, you may want to choose option 1 or 2. If you're not
sure, and we're usually not as sure as we think we are - that's why good OOP
practices exist in the first place - then you may want to choose option 3.

Dale

--
Dale Preston
MCAD C#
MCSE, MCDBA


"Josh Nikle" wrote:

I have a webform containing a GridView control "GridView1" and
usercontrol which is also a GridView "GridView2." I have a button
column in the usercontrol. The code behind that button adds an entry
to my database, which it's doing fine, but I can't get GridView1 to
show the updated data unless I browse to another page and then come
back.
>
I've been reading about using java script to accomplish this, but I
must be doing something wrong. I don't get any errors, GridView2 just
gets updated and GridView1 doesn't change. I've also noticed that
clicking refresh doesn't update GridView1 either, so maybe the java
script isn't the answer?
>
I'm very new to C#/ASP.NET, so could someone provide a sample of where
to put the script? The usercontrol (which is where I believe the
script needs to go?) uses a PreRender event rather than a PageLoad
event, if that makes any difference. Perhaps that's the issue? I've
read the numerous posts on the subject here and have been to pretty
much every blog that comes up in my browser, but no luck. I'm sure
it's something simple.
>
Any help is greatly appreciated.
>
-Josh Nikle
>
>

Oct 28 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ola Fjelddahl | last post by:
hi. I load a script dynamically and it works * everytime with IE6. * sometimes! with Mozilla1.5 <- makes me curious * never with Opera7.11 all tests on WindowsXP. With "sometimes" I mean
1
by: Marshall Dudley | last post by:
I need to be able to allow a user to submit a form which opens another window. This part I have working. But after the submit, I need to delay and have the original window do a reload. I cannot...
1
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
1
by: viktor9990 | last post by:
I have a page called CustomerSlides.aspx which contains an iframe(with the source Lookupage.aspx). The iframe page will look continuously in the database to see if a value has changed: if it is...
3
by: Raymond | last post by:
Hello folks, My script is as below: parent.menu.location.reload(true); parent.frames("menu").TreeView1.CollapseAll(); parent.frames("menu").TreeView1.SelectNodeById(id);...
1
by: =?Utf-8?B?TmVhbA==?= | last post by:
Hi How do I execute an existing script from the codebehind.. forcing a different form to do a postback and refresh itself but in it's own frame or alternatively force a reload of an aspx form...
7
by: Raffi | last post by:
I'm facing a tricky (at least for me) page reload/refresh scenario and need some help. I'm working on a web application which is primarily used with MSIE. The application has a main window with...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.