Link to home
Start Free TrialLog in
Avatar of eddyperu
eddyperuFlag for United States of America

asked on

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

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
Avatar of aibusinesssolutions
aibusinesssolutions
Flag of United States of America image

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.

Avatar of eddyperu

ASKER

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
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"
You would need to setup a delegate on your page, you can see an example here.

http://aspnet.4guysfromrolla.com/articles/031704-1.aspx
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
Actually, try this first.

protected void Close_Click(object sender, ImageClickEventArgs e)
        {
            WebForm1 cd = (WebForm1)me.Parent();
            cd.GetEnrollButton();          
        }
There is an error " The name 'me' doesn't exist in the current context
Oh, that should be this.Parent()

WebForm1 cd = (WebForm1)this.Parent();
another error:
" Non-Invocable memeber 'System.Web.UI.Control.Parent'  cannot be used like a method "
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?
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!
ASKER CERTIFIED SOLUTION
Avatar of eddyperu
eddyperu
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial