eddyperu
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="btnGetSessionStat us_Click" ImageUrl="images/GetSessio n_Button_O FF.png" />
Also I have a web user Control: "MywebuserControl.ascx" in the same page
<uc1:Summary ID="EnrollmentSummaryContr ol" 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
There is a button in my page:
<asp:ImageButton runat="server" ID="btnGetSessionStatus" onclick="btnGetSessionStat
Also I have a web user Control: "MywebuserControl.ascx" in the same page
<uc1:Summary ID="EnrollmentSummaryContr
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
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.
ASKER
What about function, I have this function in my maing page:
public void GetEnrollButton()
{
btnConfirmBenefits.Enabled = true;
btnConfirmBenefits.ImageUr l = "images/ConfirmBenefits_Bu tton_ON.pn g";
}
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
public void GetEnrollButton()
{
btnConfirmBenefits.Enabled
btnConfirmBenefits.ImageUr
}
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
ASKER
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"
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
http://aspnet.4guysfromrolla.com/articles/031704-1.aspx
ASKER
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
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();
}
protected void Close_Click(object sender, ImageClickEventArgs e)
{
WebForm1 cd = (WebForm1)me.Parent();
cd.GetEnrollButton();
}
ASKER
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();
WebForm1 cd = (WebForm1)this.Parent();
ASKER
another error:
" Non-Invocable memeber 'System.Web.UI.Control.Par ent' cannot be used like a method "
" Non-Invocable memeber 'System.Web.UI.Control.Par
ASKER
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.PageRequestMa nagerParse rErrorExce ption: 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?
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.PageRequestMa
Detailst: Error parsing near'
<!DOCTYPE HTML PBU'."
Hae you seen this error before?
ASKER
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.