call method from aspx Page into ascx Page

Hi,

I am having following code on Default.aspx which contains my User Control MenuTabs.ascx

public void Test()
{
    //my working code

******************************************************************************************************* 

 My User Control Page MenuTabs.ascx

protected void imgmyrb_Click(object sender, ImageClickEventArgs e)
{  
    Here i want to call Test() method which is available in the Default.aspx
}   

protected void imgmyskills_Click(object sender, ImageClickEventArgs e)
{
       Here also i want to call Test() method which is available in the Default.aspx
}

Means in short i want to call Test() method which in the Default.aspx on the both image click event in the User Control i.e MenuTabs.ascx

 

0
rohitjpuranik
10/17/2008 9:38:49 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

3 Replies
1263 Views

Similar Articles

[PageSpeed] 41

Hi there,

The user control has a page property, so you can just this property to your pageclass and access the method, like so

MyPageClass page = Page as MyPageClass;
if (page != null){ page.Test(); }


Hope this helps !
Rinze Cats

---------
please select 'mark as answer' if this post helped you!
0
Rinze
10/17/2008 4:45:11 PM

 Thanks Rinze for ur reply But how can i do this plz will you explain me using the above example which i have mentioned. If you will consider the above example and give me your response with proper explanation that will be more better for me,
 

0
rohitjpuranik
10/18/2008 7:22:20 AM
protected void imgmyrb_Click(object sender, ImageClickEventArgs e)
{  
MyPageClass page = Page as MyPageClass;
if (page != null){ page.Test(); }  

}   

protected void imgmyskills_Click(object sender, ImageClickEventArgs e)
{
      MyPageClass page = Page as MyPageClass;
      if (page != null){ page.Test(); }
}

The test method you place in your codebehind file, i.e. default.aspx.cs. In the above example, you have to replace 'MyPageClass' with the classname of your codebehind file. So the above would work if your codebehind looked like this:

public partial class MyPageClass: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void Test(){
       
        }
   }


Hope this helps !
Rinze Cats

---------
please select 'mark as answer' if this post helped you!
0
Rinze
10/18/2008 8:03:17 AM
Reply:

Similar Artilces:

Calling a method from a control page on the axpx page where the control page exists.
Hello,  I have an .aspx page that has a method called grdMain_DataBind().  I have a control page that loads within the aspx page which has its own logic.  I have a button on my control page called "SAVE".  How can I call the method grdMain_DataBind thats in my aspx logic from the control that exists on that page when I click SAVE button.  Is there a way? If I were you, I'd simply create a "Save" Event within your control. When the Button in your control is pressed, in the Click handler for that Button you can raise the event. Then, within t...

Call codebehind method from aspx page OR call javascript function of usercontrol control from page
Hi, I have a page which contains a user control.  When a user clicks on a submit button, I'd like to detect when elements in the user control have changed and popup a message box if changes have been detected to confirm if the user wants to save the changes. Obviously the message box is executed using javascript.  But I'd really like to be able to call a method in the code behind of the page which queries the user control if it has changed.  Is there a way of calling the code behind method from within a javascript function? Otherwise, if I make all the functions execut...

Can I call a method on aspx page thru the method of control(ascx)
Can I call a method on aspx page thru the method of control(ascx)Ajay Pathak MVP All About ASP.net better u can createa method in class and access from ascxHAPPY CODINGhttp://shobhitrai.blogspot.com/ Your question is not clear to me, You mean to call method which is in aspx form ascx??Imran[MCTS]Few have audacity to speak truthhttp://knowledgebaseworld.blogspot.com/ Hi, Please refer the following code,  uc.ascx:<%@ Control Language="C#" ClassName="uc" %> <script runat="server"> protected void Page_Load(object sender, EventAr...

Call public method on aspx page from a web control embedded in the page
I have a nut to crack. How do I call a public method on my aspx page from my web control, the web control is embedded into the page. The markup looks like this:-   1 <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 2 <ContentTemplate> 3 <asp:Xml ID="Xml1" runat="server"></asp:Xml> 4 <uc2:tier3menu ID="menu1" runat="server" /> 5 </ContentTemplate> 6 </asp:UpdatePanel> I wrote an itemcommand thingie in the web control that needs to set the Documentsource a...

Calling an .aspx page from an .ascx page
I have the following control: TrackerMain.ascx <%@ Register TagPrefix="Portal" TagName="Title" Src="~/controls/DesktopModuleTitle.ascx" %> <%@ Register TagPrefix="date" Namespace="PeterBlum.PetersDatePackage" Assembly="PetersDatePackage" %> <%@ Control Language="vb" AutoEventWireup="false" Codebehind="TrackerMain.ascx.vb" Inherits="DotNetNuke.TrackerMain" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <portal:title id="Title1&quo...

Controlling ascx page in aspx page
Hi all, Im totally new in asp.net and i have a few questions. I have several page's and on each page i use a header.ascx to display the header on each aspx page. How can i control for example a label (lblCustom.text, lblCustom.visible) wich is placed in my ascx file with code in my aspx page ?? My second question?? I want to email some information to several people in my web application. The problem is the content of the email is not displayed very nice, for example username:.......test password: ...................abcdfdf Address: .....teststreet (the dots are ...

How to pass textbox control value from UserControl page(ascx) to Page Control(aspx).
I have 2 files(aspx and ascx). the aspx page  has a Web user control(ascx) in it.Once the button control click(in aspx) I want to get the value from the textbox(ascx) controland pass it to label control in aspx page.Can somebody help with this and please use VB.Thanks A simple search would have turn up many different solutions.  The easiest is to just expose the textbox value as a property in your control.  Then you can retrieve that value on the aspx page. Add this to your control: Public Property TextBoxValue() As String   Get   &...

Control Menu in ascx page from aspx page
Hi all, Hope you can help. I have a menu in an ascx page that I want to change the visible status on based on whether a user is authenticated or not. If on the aspx page I try to change the state of the menu, I get the error that the menu is protected. I have very limited programming experience and can't find any info on this All help is welcome   Argy     In the Page_Load() Event, do this: If Page.User.Identity.IsAuthenticated = True Then Menu1.Visible = False Else Menu1.Visible = True End If  Specializing in...

Calling a method written in .cs page from aspx page
Can we able to call a method coded in aspx.cs page from an asp control?This way:eg.aspx page----------<asp:TextBox ID="txtbox1" runat="server" OnTextChanged=<b>GetText()</b>></asp:TextBox>aspx.cs page------------public void GetText(){} Yes.  But the easiest way to set this up to ensure it works is to double-click the text box in Design View.  That will automatically add the OnTextChanged event handler to the text box, and create the beginnings of the method for your code:<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="...

Calling methods on aspx and ascx pages ?
Hi,Is it possible to call methods on .aspx.cs and .ascx.cs pages rather than only on .asmx.cs ?Thank you,Steve. Yes, just attribute your methods as WebMethod's in your page/user controls. The code that is emitted, allows you to do a PageMethods.MethodName call to execute it via Javascript, or if you're declaratively using it, use pageMethod instead of serviceMethod. You should also note that in pageMethod, you don't need to specify a url.Matt Hawley Have you actually tried this and managed to get it to work? I know the theory but even on simple methods I get an exception raised that sug...

How to get user control id of ASPX page from ascx page..
Hi I have 1 user control which i m using in my aspx page 3 times..... my problem is that i want to get all these thee id of user control (which is in aspx page) from ascx page...whenever any button is clicked within user control....lets have a sample...<uc:RTB ID="RTBText" runat="server" RichTextBoxHeight="130"/><uc:RTB ID="RTBSummary" runat="server" RichTextBoxHeight="130"/><uc:RTB ID="RTBAffilation" runat="server" RichTextBoxHeight="130"/> here 3 user control i have de...

how can i call controls from ascx (in aspx page)
hi , i have page.aspx and i create 2 a.ascx and 1 b.ascx in onInit page.aspx page.aspx code behind - OnInitfor (int i = 0; i < 2; i++) {Control c = this.LoadControl("~/a.ascx"); c.ID = "c_" + i.ToString();this.Panel1.Controls.Add(c); }Control c = this.LoadControl("~/b.ascx"); c.ID = "c_" + i.ToString();this.Panel1.Controls.Add(c); ---------------- i create dynamic 2 a.ascx and 1 b.ascx in page.aspx. a.ascx have 1 buton , 1 textbox and 1 label b.ascx is same. i want to take a.ascx and b.ascx textbox.text and want to click butons... ...

Paging Paging Paging
I am trying to do paging with my search results and it isnt working very well. Here is what I've tried and I feel I've tried everything, lol, please help me out. Sub DataGrid1_SortCommand(Sender as object, e as DataGridSortCOmmandEventArgs) DataGrid1.DataBind() End Sub Sub Datagrid1_PageIndexChanged(Sender as object, e as DataGridPageChangedEventArgs) Dim ds as dataSet DataGrid1.CurrentPageIndex = e.NewPageIndex if Session("Search") is nothing then 'Session probably has expired, get the datasource from database Datagrid1.DataSource = ...

issue:not able to get ID of Control in aspx page on .ascx page
hai there, im trying to get the ID of the control  which im using  .ASPX page  into  the  .ASCX page Is that possible?assume that having  a grid in aspx page and an usercontrol in .ascx page(one textbox and a submit button) here i want to update  the DB and reflect in the grid  once i click the submit button,since its is a user control click event i have writen  submit_click event in  .ASCX, here i was not able to get the grid id to bind the data to it   is that possible,prakash      One sim...

Web resources about - call method from aspx Page into ascx Page - asp.net.navigation-controls

Talk:Comparison of cash and accrual methods of accounting - Wikipedia, the free encyclopedia
This article is within the scope of WikiProject Taxation , a collaborative effort to improve the coverage of tax -related articles on Wikipedia. ...

Where's the best school to study VCE English, maths methods and sociology?
Lena Hudson broke down in tears in the Keilor Downs College staff tearoom when she heard how well her VCE students had performed.

ISIS recruitment methods exposed after Jordanian woman flees secret compound
A Jordanian woman who came close to joining the Islamic State group described a sophisticated 14-month recruitment process by the extremists ...

Business schools ranking methods and sources - Business Insider Deutschland
How we put together our ranking of the best business schools in the world

Chipotle to tweak cooking methods
The Mexican grill will be tweaking some of its cooking processes after an E. coli outbreak sickened more than 50 people.

Have You Stayed Current On Your Dishwasher-Loading Methods?
We’ve long emphasized the importance of not pre-rinsing dishes for your newer dishwasher, since modern appliances now assume that you don’t. ...

You might be able to get P.T. back with this risky third-party method
... Kojima, all the while making his life a living hell throughout 2015 But alas, if you don't have P.T. on your PS4 anymore, there is a method ...

Decoding Arvind Kejriwal: His method is his statement and here's why he is not going to change
Kejriwal confused us all as an anti-corruption crusader and as a politician, he continues to be a riddle.

Why Trust A Theory? Physicists And Philosophers Debate The Scientific Method
This week, a group of about 100 physicists and philosophers have gathered in Munich to reassess a question at the heart of science: “Why trust ...

Why 30-Year-Old Computer Hacking Methods Still Work
A system is only as secure as the end user, as any grey-haired sysadmin will happily tell you. As a result, all the alphanumeric passwords in ...

Resources last updated: 1/2/2016 4:24:51 AM