By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Having trouble with script to reload parent page?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.