?
Solved

How can I call a control inmy page from a web user control?

Posted on 2009-02-16
12
Medium Priority
?
354 Views
Last Modified: 2012-05-06
Hi,
There is a button in my page:
<asp:ImageButton runat="server" ID="btnGetSessionStatus" onclick="btnGetSessionStatus_Click" ImageUrl="images/GetSession_Button_OFF.png" />

Also I have a web user Control: "MywebuserControl.ascx" in the same page
<uc1:Summary ID="EnrollmentSummaryControl" runat="server" ></uc1:Summary >
Inside this Web User Control I have a button like this:
 <asp:ImageButton runat="server" ID="set" ImageUrl="images/Close.png"
                                    onclick="Close_Click" />
In the codebihind of the web user control I have this:
        protected void Close_Click(object sender, ImageClickEventArgs e)
        {
         // I want to be able to call the "btnGetSessionStatus" here, and change some attributes like enabled="false" , how can I do this???
        }

Thanks
0
Comment
Question by:eddyperu
  • 8
  • 4
12 Comments
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23654061
You'll probably be better off using javascript to enable/disable the buttons, since the controls on the page aren't declared as public controls.

0
 
LVL 4

Author Comment

by:eddyperu
ID: 23654111
What about function, I have this function in my maing page:
        public void GetEnrollButton()
        {
            btnConfirmBenefits.Enabled = true;
            btnConfirmBenefits.ImageUrl = "images/ConfirmBenefits_Button_ON.png";
        }

How can the web user control call this function with the click of the button? Would you mind to show me some examples with my code!
Thanks
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23654144
I have tried:
        protected void Close_Click(object sender, ImageClickEventArgs e)
        {
            WebForm1 cd = new WebForm1();
            cd.GetEnrollButton();
           
        }
But there is an error that says:
- " Object reference  not set to an instance of an object"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23654149
You would need to setup a delegate on your page, you can see an example here.

http://aspnet.4guysfromrolla.com/articles/031704-1.aspx
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23654212
Thanks, but I am new in C# and vb. the example is in vb.net. Would you mind to send me an example in c# or write an example using my code. I wan to study the procedure that you are taking to create a delegate and use it.
By the way. For what reason I will use a delegate here?
thank you so much
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23654343
Actually, try this first.

protected void Close_Click(object sender, ImageClickEventArgs e)
        {
            WebForm1 cd = (WebForm1)me.Parent();
            cd.GetEnrollButton();          
        }
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23659415
There is an error " The name 'me' doesn't exist in the current context
0
 
LVL 15

Expert Comment

by:aibusinesssolutions
ID: 23659424
Oh, that should be this.Parent()

WebForm1 cd = (WebForm1)this.Parent();
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23659634
another error:
" Non-Invocable memeber 'System.Web.UI.Control.Parent'  cannot be used like a method "
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23659904
hi aibussnesssolution for all your help  but I sore it of found the answer, I think :

What I did to fix this problem is just create a dummy button to be attached to the modal pop up extender and then call the Modal pop up extender from an event of a button  " ModalPopup.show() "
Also, I created an asp button inside the modal pop up extender that will render to the server side  and will change the attributes of the button in the main page. Like you say trying to access the buttons from the web user control can be tricky specially because they are privates.
I still have an update panel that wrap all this:
New problem : a message appears"
  Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common cause for this error are when the response is modified by calls to Response.Write(),response filters, HttpModules, or server trace is enanbled.
Detailst: Error parsing near'
<!DOCTYPE  HTML PBU'."

Hae you seen this error before?
0
 
LVL 4

Author Comment

by:eddyperu
ID: 23662737
I ifc the proble iwth that error.
I have a Server.transfer inside the event . It looks like update panel and server transfer don't like each other somthing to do with the way how update panel is rendering the page.
Anyhow to solve this problem I switch it to Response.Redirect and  now it is working great!
Thanks aibusinesssolutions for your help!
0
 
LVL 4

Accepted Solution

by:
eddyperu earned 0 total points
ID: 23664901
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question