Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system.web.ui.control._page' is not accessible in this context because it is 'friend' 1

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
0
0
US

I have a procedure "Protected Sub BtnDimSubmit_Click(sender As Object, e As EventArgs) Handles BtnDimSubmit.Click"

In my immediate window I can view the sender information

"?DirectCast(DirectCast(sender,System.Web.UI.WebControls.Button)._page,ASP.quotes_aspx).DDLcontainer2.SelectedValue"
The value returned is ("DRM") which is correct.

I need to test the value at run time however when I try to use the "DirectCast(DirectCast(sender,System.Web.UI.WebControls.Button)._page,ASP.quotes_aspx).DDLcontainer2.SelectedValue"

I get an error before I even run it stating " 'system.web.ui.control._page' is not accessible in this context because it is 'friend' "
I've tried assigning the statement to a string and object with no luck.

Any Ideas

Thanks

-dan
 
I have to ask why you are writing code like this. What exactly are you trying to do?:
Code:
 "DirectCast(DirectCast(sender,System.Web.UI.WebControls.Button)._page,ASP.quotes_aspx).DDLcontainer2.SelectedValue"

Are you in a user control and trying to get the button that caused a postback from the page?
 
Hi JB

I have a ajax popup modal extender opening an panel containing an ascx control.
folks enter data in 3 TB's Length, Width, height.
They next press the submit button on the ascx control firing the procedure
"Protected Sub BtnDimSubmit_Click(sender As Object, e As EventArgs) Handles BtnDimSubmit.Click"

In this procedure I was trying to see in the sender what the control on the parent form ( a DDL) value was to handle in a IF clause.
I put a break point in the Sub and was looking at the sender object to determine which control passes the value in.

I put my hover over the sender object and pass down until I saw this

"DirectCast(DirectCast(sender,System.Web.UI.WebControls.Button)._page,ASP.quotes_aspx).DDLcontainer2.SelectedValue"

I dropped it into immediate window. and it shows the value as ("DRM") .

In short Im trying to read the passed in value from the parent form.

Hope this Helps







 
So now I think I am even more confused. Let me see if I have this.
You have a page with a ddl called DDLContainer2. When a user changes the value you open up a model dialog with a user control in it.
When the user clicks the submit button on the usercontrol, you want to get the selected value in DDLcontainer2.

Is that correct?
 
Actually the user selects a value from a dropdown list. Then user clicks a button near it (buttons are ID 1 - 5) which opens the popup modal extender (also number 1-5) containing the three text boxes which the fill in. On the open modal popup user clicks the submit button. When user clicks the submit button on the modal popup I want to read the value of the Dropdownlist that associates with the button.





 
Ok, much clearer now.
There are 2 ways I can see doing this.

1.)Pass the ddl value as a query string value when you open the modal dialog and have the user control read it.

2.)Create a property on the user control. When the user clicks the button(1 - 5) set the property on the user control with the ddl value.(This is the way I would do it)
 
Thanks,

I like option #2. Can you nudge me in the right direction on setting a usercontrol proerty?
 
You just create a property on the user control like you would on a page:
Code:
public property ddlValue as string

Register your user control on the page:
Code:
<%@ Register Src="~/relative path to your usercontrol/yourUserControl.ascx" TagName="ucMyUC" TagPrefix="uc1" %>

Place the user control on the page
Code:
<uc1:ucMyUC ID="ucMyUserControl" runat="server"></uc1:ucMyUC>

Set the property on the user control from whatever event you need:
Code:
ucMyUserControl.ddlValue = DDLcontainer2.SelectedValue
 
Ok Thank you very much. I'll give it whirl here in a little while. I'm juggling a few things and that one hasn't come back down yet :)

 
jbenson001

Had to do a change up. Seems I'm going to call the same control from other pages.
What I wound up doing with the popup modals button click event was...

If parent.ID = ("BlaBlah") then
DDLvalue = CType(Parent.FindControl("DDLcontainer1"), DropDownList).SelectedValue


end if


Just posting this in case somebody else runs into my dilemma.

Thanks Again. :)
 
You are not implementing the code I sent you. Do not set the value of the property in the user control code behind. You set the user control's property from the page's code behind that it is on.

The purpose of a user control is so that it can be reused on multiple pages. What you are doing is tying to the page, which you don't want to do.
Again, in the page's code behind:
Code:
maybe put this in the ddl's selectedindexchanged event ON the PAGE
ucMyUserControl.ddlValue = DDLcontainer2.SelectedValue

Let me know if you have quesitons.
 
jbenson001

The selectedundexchange and although I wasnt using that even I can use it.
What's bugging me is I had tried you first option (#2) above.

I registerd the UC ("FgtDimensions.ascx") on my page "Quotes.aspx"

<%@ Register Src="~/FgtDimensions.ascx" TagPrefix="uc1" TagName="FgtDimensions" %>

I have the control ID set in the modal Popup extender firing off of my "BTNdims1" button.

<uc1:FgtDimensions runat="server" ID="FgtDimensions1" />

I've created the value "Public DDLval1 as String" on my UC.

But my intellisense will not display "FgtDimensions1" so I can't assign FgtDimensions1.DDLval = DDLcontainer1.SelectedValue .

I think I missed something along the way :(




 
Possibly the definition of the UC on the page
Code:
<uc1:FgtDimensions runat="server" ID="FgtDimensions1" />
try changing to
Code:
<uc1:FgtDimensions runat="server" ID="FgtDimensions1" /></uc1:FgtDimensions>

also make sure the property on the UC is Public
 
Tried it but it didn't help.

Here's the script on the 1st button.

<asp:UpdatePanel ID="UPpnlDims1" runat="server">
<ContentTemplate>
<asp:Button ID="BtnDims1" runat="server" Text="Dim" Width="31px" Font-Size="XX-Small" ToolTip="Enter Dimensional Load Information" TabIndex="11" style="height: 21px" />
<ajax:ModalPopupExtender ID="BtnDims1_Mpe" runat="server" Enabled="True" TargetControlID="BtnDims1" PopupControlID="PNLfgtDimension1" DropShadow="true">
</ajax:ModalPopupExtender>
<asp:panel ID="PNLfgtDimension1" Style="display: none;" runat="server" BorderColor="#212020" BorderStyle="Double" Visible="true" BorderWidth="6px" Width="440px" Height="150px" BackColor="White">
<uc1:FgtDimensions runat="server" ID="FgtDimensions1"/>
</asp:panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="BtnDims1" />
</Triggers>
</asp:UpdatePanel>
 
You should be able to make the code I gave you work. I don't know if any of those AJAX controls are interfering somehow. I don't use them. I use JQuery and JQuery UI.
I don't think they should do anything. You need to check syntax and the registration of the UC again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top