473,394 Members | 1,746 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,394 software developers and data experts.

Is it possible to call a method defined in AnotherPage.aspx.cs?

I know that we can re-use/share code by placing the code in App_Code.

But, is it possible for MyPage.aspx.cs to call a method defined in
AnotherPage.aspx.cs?

Suppose, in AnotherPage.aspx.cs, we define a method which binds a
DropDownList to a database table. Let's call the method
BindDropDownList().

In MyPage.aspx, we are gonna use the same DropDownList. Is it
possible, in MyPage.aspx.cs, to simply instantiate AnotherPage and
call BindDropDownList()? Something like

// This is MyPage.aspx.cs
AnotherPage anotherPage = new AnotherPage();
anotherPage.BindDropDownList();

Does this sound whimsical?

I guess the answer is Nope, and we better write a generick-ish
BindDropDownList and stick it in a class under App_Code, right?

Oct 25 '07 #1
8 1810
"gnewsgroup" <gn********@gmail.comwrote in message
news:11**********************@v3g2000hsg.googlegro ups.com...
In MyPage.aspx, we are gonna use the same DropDownList.
Sounds like a perfect candidate for a UserControl...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 25 '07 #2
On Oct 25, 3:23 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"gnewsgroup" <gnewsgr...@gmail.comwrote in message

news:11**********************@v3g2000hsg.googlegro ups.com...
In MyPage.aspx, we are gonna use the same DropDownList.

Sounds like a perfect candidate for a UserControl...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Thanks, that must be the solution. I find it hard to pass variables
amongst user controls, though.

Oct 25 '07 #3
"gnewsgroup" <gn********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
In MyPage.aspx, we are gonna use the same DropDownList.

Sounds like a perfect candidate for a UserControl...

Thanks, that must be the solution. I find it hard to pass variables
amongst user controls, though.
Just use public properties...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 25 '07 #4
On Oct 25, 3:49 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"gnewsgroup" <gnewsgr...@gmail.comwrote in message

news:11**********************@k79g2000hse.googlegr oups.com...
In MyPage.aspx, we are gonna use the same DropDownList.
Sounds like a perfect candidate for a UserControl...
Thanks, that must be the solution. I find it hard to pass variables
amongst user controls, though.

Just use public properties...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
I've tried out your idea, and it was successful. That's great, but,
what about event-raising and event-consuming amongst user controls?

Say, I want user control A to respond to a click event of user control
B. Public properties won't do the trick, right?

Oct 26 '07 #5
"gnewsgroup" <gn********@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
I've tried out your idea, and it was successful. That's great, but,
what about event-raising and event-consuming amongst user controls?

Say, I want user control A to respond to a click event of user control
B. Public properties won't do the trick, right?
Ah yes - for that, you need delegates:
http://www.netomatix.com/development/usercontrols3.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 26 '07 #6
On Oct 26, 11:23 am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"gnewsgroup" <gnewsgr...@gmail.comwrote in message

news:11**********************@19g2000hsx.googlegro ups.com...
I've tried out your idea, and it was successful. That's great, but,
what about event-raising and event-consuming amongst user controls?
Say, I want user control A to respond to a click event of user control
B. Public properties won't do the trick, right?

Ah yes - for that, you need delegates:http://www.netomatix.com/development/usercontrols3.aspx

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Fantastic. I did write a user control which has a GridView. This
GridView gets populated with customer names retrieved from the
database. The customer names in the GridView are made to be
LinkButtons (in template fields). When such a LinkButton'ed name is
clicked, I want to send the name as a string to the parent control.

Let's call this user control SearchCustomers.ascx.

I followed the example you gave in the link above, and successfully
made the whole thing happen, which kinda excited me. Thank you.

But, I do not want to show SearchCustomers user control in the parent
page until a button is clicked in the parent page.

I have written a Visible property in SearchCustomers.ascx.cs, like so:

private bool visible;

protected void Page_Load(object sender, EventArgs e)
{
if (this.visible)
{
Panel1.Visible = true; // Pane1 holds the GridView.
}
else
{
Panel1.Visible = false;
}
}

public bool Visible
{
get
{
return this.visible;
}
set
{
this.visible = value;
}
}

In ParentPage.aspx's Page_Load, if I say

SearchCustomers1.Visible = true;

This control does show up nicely, but if I attempt to set the Visible
property in the button click event handler like so:

protected void btnSearchCustomers_Click(object s, EventArgs e)
{
SearchCustomers1.Visible = true;
}

The SearchCustomers1 user control does not show up. I kinda suspect
that it is because it has passed the Page_Load event, so the control
cannot be rendered. In any case, how do I show/hide a user control
dynamically? Somehow, I guess this user control has to be recreated /
reloaded, but what do I need to do?

Thank you again if you could share your wisdom.

Oct 26 '07 #7
"gnewsgroup" <gn********@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
The SearchCustomers1 user control does not show up. I kinda suspect
that it is because it has passed the Page_Load event, so the control
cannot be rendered. In any case, how do I show/hide a user control
dynamically? Somehow, I guess this user control has to be recreated /
reloaded, but what do I need to do?
I suspsect you're right.

It's a little difficult to tell without the rest of the app around the above
code, but I'd start by setting a breakpoint at the beginning line of each
method, and watching the Visible property. Remember that when you set a
control's Visible property to false server-side, it doesn't hide the
control - it actually doesn't render it at all, so it never gets streamed
down to the browser...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 26 '07 #8
On Oct 26, 2:31 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"gnewsgroup" <gnewsgr...@gmail.comwrote in message

news:11**********************@d55g2000hsg.googlegr oups.com...
The SearchCustomers1 user control does not show up. I kinda suspect
that it is because it has passed the Page_Load event, so the control
cannot be rendered. In any case, how do I show/hide a user control
dynamically? Somehow, I guess this user control has to be recreated /
reloaded, but what do I need to do?

I suspsect you're right.

It's a little difficult to tell without the rest of the app around the above
code, but I'd start by setting a breakpoint at the beginning line of each
method, and watching the Visible property. Remember that when you set a
control's Visible property to false server-side, it doesn't hide the
control - it actually doesn't render it at all, so it never gets streamed
down to the browser...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
Thank you. I only recently realized that setting Visible to false
server-side will cause the server not to render it.

Well, the trick is to put SearchCustomser1 on a Panel, and then show/
hide the panel instead.

Oct 26 '07 #9

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

Similar topics

7
by: Tiraman | last post by:
Hi , I have 3 files , middle.aspx file include the header.aspx and footer.aspx files . in each of the include files there is a function and from some reason the call to the Footer() function...
1
by: Ed Chiu | last post by:
Hi, I createed a user control named fnCalender.ascx, there is a method called getInfo defined in calender.ascx. I drag and drop this control into a web form then I tried to call the method...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
4
by: David Freeman | last post by:
Hi There! I'm just wondering if there's a way to pass parameters (as if you were passing parameters to a ASCX web control) when calling an ASPX page? e.g. MyDetailsPage.UserName = "david" ...
2
by: SteveSu | last post by:
Hi! I want to make a postback when the user hits the escape-button on the keyboard and redirect the user to another page. But the response.redirect does not work for me in this "context". I´m...
2
by: Progman | last post by:
Id like to call another aspx page from a script area from a procedure. the only way i found is: Me.Controls.Clear() Server.Execute("AnotherPage.aspx) Is there a better way?
6
by: Steve Richter | last post by:
what with the website solution structure not having a namespace, how does the class of one website .aspx page class reference the class of another page in the same website? I have two pages....
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
5
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.