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
Microsoft TechEd India 2009


0
ajaypathak
8/25/2008 6:22:09 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
803 Views

Similar Articles

[PageSpeed] 27

better u can createa method in class and access from ascx


HAPPY CODING
http://shobhitrai.blogspot.com/
0
shobhit
8/25/2008 6:35:50 AM

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 truth
http://knowledgebaseworld.blogspot.com/
0
bhadelia
8/25/2008 8:26:44 AM

Hi,

Please refer the following code, 

uc.ascx:

<%@ Control Language="C#" ClassName="uc" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string GetConnection() 
    {
        return "the connection string goes here";
    }
</script>

Page.aspx: 

<%@ Page Language="C#" %>

<%@ Register src="uc.ascx" tagname="uc" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(uc1.GetConnection());
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <uc1:uc ID="uc1" runat="server" />
    
    </div>
    </form>
</body>
</html>
 
Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
8/29/2008 7:32:47 AM

 

hi Ajay,

1. Expose an event in user control

2. Handle it inside the page's codebehind with a method.

3. In side that method you can call any methods of the page.

4. Invoke this event any where in user controls depending on your need.

 

 


Bharath
0
member1
8/29/2008 8:39:21 AM
Reply:

Similar Artilces:

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...

Can I have a web user control call a method on the page it's parent page?
I'm building an application where I'm using serveral different controls on a page and as one of them causes a postback I may want the page to make changes to other controls.  Is there a way to either fire and event off from the control that the page could then capture or simply have the control call a method of it's parent page? Obviously the Page object is there to work with, but I can't seem to figure out how to specifically cast it as a specific page.  For real man, In your user control you need to create a public event which is raised by the event of the...

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...

call method from aspx Page into ascx Page
Hi,I am having following code on Default.aspx which contains my User Control MenuTabs.ascxpublic void Test(){    //my working code} *******************************************************************************************************  My User Control Page MenuTabs.ascxprotected 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){       H...

error when calling a web services method from a winform control in an aspx page
I've put a winform control into an aspx page, inside an 'object' tag and I'm having it call a web service method.The control runs fine when I debug it in VS, and the control itself loads into the web page when I view it over the internet in IE, but when I click the button to call the web services method (it  sends a string to a label in the control) I get the following error message...and the string is not returned to the label...System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToke...

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...

can i refer from the autocomplete web service(or page method) to other controls on the page ?
i want to be able to read the value of a textbox control from within the autocomplete web service (or page method) but i doesn't recognize this controls directly. can it be done ?   Not like I think you want. How would the remote web service know the text in the textbox?http://blogs.msdn.com/DelayThis posting is provided "AS IS" with no warranties, and confers no rights....

how can I call a method in static web service method?
I have a web service method like below that I want to call a edit method in it, hiw can I do that?it cuse error in it.[WebMethod] public static string getText() { } and a method like this?  public void edit() { int a=textbox1.text  } thanx Either you have to declare edit() also as static or create an object of the class and call edit. Hi  sepideh_adi, If you want to use method of webservice, you should reference it firstly. WebSite->Add WebReference->Fill webservice url and webrefernce Name. Then you can use the webservice. webrefernceName tt=new webref...

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 can I pass additional parameters to the web service or how can I call a method in the code behind page.
I have done a ton of research in this area and there just does not seem to be a way to pass any addiional parameters to the Web Service reference in the autoextneder call.  Is there a way that this can be done.  In my world, the list of suggestion is dependant on other data on my web form or web user control.   I had read some references that you might be able to call a method in the code behind page, however everything i have tried on this has failed.  Here is a list of what I have attempted  Tried to add query string arguments to the service path property (er...

Calling a Page Method Instead of a Web service method with javascript?
Hi All,I am just wondering if it is possible to call a page method or a static method (non webservice) with javascript and have it return the results to the calling javascript funciton just like how it is done with a webservice call? Personally I prefer not to be producing asmx's for things that may only be used on a single page. If so ... how might I accomplish this?If Not..... Why not?heheThanks Hi miskiwYes you can do that, you can find details herehttp://ajax.asp.net/docs/tutorials/useWebServiceProxy.aspx at the bottom of the page titled "To call a static page method".It is wo...

How can I call web-form method from UserControl?
How can I call web-form method from UserControl, if i don't use code-behind? I'am try this:((ASP.view_aspx)this.Page).Voting(); (Where Voting()- the public method of web-form, view_aspx=filename_aspx.) but i catch the error:The type or namespace name 'view_aspx' does not exist in the class or namespace 'ASP' (are you missing an assembly reference?) If i see Page.ToString() i get "ASP.view_aspx". That very suspicious. Thanks you for your help.--- Pavel Andreevich That object is for compile and execute purposes by ASP.NET itself. Unfortunately, when the page with the a...

How can I call web-form method from UserControl?
How can I call web-form method from UserControl, if i don't use code-behind? I'am try this:((ASP.view_aspx)this.Page).Voting(); (Where Voting()- the public method of web-form, view_aspx=filename_aspx.) but i catch the error:The type or namespace name 'view_aspx' does not exist in the class or namespace 'ASP' (are you missing an assembly reference?) If i see Page.ToString() i get "ASP.view_aspx". That very suspicious. Thanks you for your help.--- Pavel Andreevich...

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... ...

Web resources about - Can I call a method on aspx page thru the method of control(ascx) - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

TERROR IN JAKARTA: 'Situation under control' after explosions, gunfire erupt in Indonesian capital
At least six people are dead, including three police officers, after several explosions at the Sarinah shopping mall in an apparent multi-site ...

DFES downgrades bushfire in Dunsborough as it is contained, but not under control
A BUSHFIRE south of Dunsborough has been contained but is not yet under control.

WA fires: threatening Jindalee blaze brought under control
A fire that was at one stage a threat to lives on homes in Jindalee on Thursday has been brought under control.

Queensland police shut down out-of-control party in Berserker, Rockhampton
Police shut down a party of 150 young people who had gathered at a house in Berserker, Rockhampton on Friday night.

BMW recalls i8 for stability control problem
... , BMW , Safety , Coupe , Hybrid , Performance BMW will recall a small number of 2015 i8s because of a problem with the dynamic stability control ...

ESI cost control and networks
There is an interesting discussion thread on Twitter about how the way Medicare for All saves money is by significantly reducing provider, device, ...

While No One Was Watching, Obama Took Control of the Courts
... and President Obama’s legacy.” It didn’t favor conservatives but there was a dramatic shift to the far left. The appellate is under the control ...

Apple has landed a very rare sponsorship deal to ensure it has control of the hottest ticket in San Francisco ...
Apple has signed up for the first time to become a sponsor of the Super Bowl Host Committee, Daniel Roberts at Yahoo Finance reported. It's ...

Leonardo DiCaprio: The Oscar stuff is ‘completely beyond my control at this point’
... last night’s London premiere of The Revenant . Leo is looking pretty good these days. He’s de-bloated, his facial hair is very much under control, ...

Resources last updated: 1/17/2016 12:22:53 AM