Linking two controls in two seperate .ascx files

hello,

im trying to make a couple of image buttons in one usercontrol affect the ActiveViewIndex state of my multiview in another control so far both codebehinds look like this...

1: this is where the multiview is located, the MV is called contents

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
    public partial class UserControls_Content : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }
        public MultiView SetActiveViewIndex
        {
            get
            {
                return this.contents.ActiveViewIndex;
            }
        }
        protected void testMenu_MenuItemClick(object sender, MenuEventArgs e)
        {
            int index = Int32.Parse(e.Item.Value);
            contents.ActiveViewIndex = index;
        }
    }
*Note: i included a simple asp menu control just to test the multiview works prior to doing all the code.

2: this is where the image buttons are located, each one has a click event that changes a submenu active viewand hopefully the contents active view.

*the buttons are named ecLink pmLink and rsLink

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_mainMenu : System.Web.UI.UserControl
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void pmLink_Click(object sender, ImageClickEventArgs e)
    {
        subMenu.ActiveViewIndex = 0;
    }
    protected void rsLink_Click(object sender, ImageClickEventArgs e)
    {
        subMenu.ActiveViewIndex = 1;
    }
    protected void ecLink_Click(object sender, ImageClickEventArgs e)
    {
        subMenu.ActiveViewIndex = 2;
    }
}

 my problem occours is that i dont no how to code together both usercontrols to make one affect the otherTongue Tied

hope you can help!

thanks 

0
ops_rob
5/5/2007 11:12:30 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

5 Replies
618 Views

Similar Articles

[PageSpeed] 26

In the webcontrol with multivew put this code in the Page_Load section:

HttpContext.Current.Items["myMultiview"] = myMultiview; (or whatever the name of your multiview is)

In the other user control with the button click do this:

((MultiView)HttpContext.Current.Items["myMultiview"]).ActiveViewIndex = 1; (or 2 or 3 or whatever)

Peace,


-Timothy Khouri
http://www.SingingEels.com/
Developer / Architect / Author
0
Nullable
5/6/2007 1:27:54 AM

Tying the two User Controls together in this way is not recommended. You shoudl be exposing events on each user control and consuming them as neccessary. Is one inside the other?

User Control with PMClick Event.

  

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CSharp_UCOne : System.Web.UI.UserControl
{

    public event EventHandler PMClick;

    protected void OnPMClick(EventArgs e)
    {
        if (PMClick != null) {
            PMClick.Invoke(this, e);
        }
    }
    // The link button click event delegate
    protected void pmLink_Click(object sender, EventArgs e)
    {
        // Raises User Control Public Event
        OnPMClick(e);
    }
}
 

Page Consuming PMCLick Event - could be a parent user control.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CSharp_Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // My User Control Instance is UCOne1 (yeah I know its real tidy)
        this.UCOne1.ID = "mainMenu";
        this.UCOne1.PMClick += new EventHandler(MainMenuPMClicked_Handler);
    }
    private void MainMenuPMClicked_Handler(object sender, EventArgs e) {

        // do actions
        Response.Write("PM Clicked");
    
    }
}
 

 


Rgds,
Martin.

For the benefit of all users please mark any post answers as appropriate.
0
mokeefe
5/6/2007 6:10:27 AM

What I was referring to above is found in this article: http://www.singingeels.com/ArticleView.aspx?ArticleID=22

Peace,


-Timothy Khouri
http://www.SingingEels.com/
Developer / Architect / Author
0
Nullable
5/7/2007 3:02:10 AM

Hi Timothy,

I wasn't trying to be big footed; especially as I have previously noted the quality of your posts.

However, I am inclined to push people towards more longer term solutions, or ones that provide for a better understanding of the toolset.

"So in conclusion, if you need to tie your web application together, but you're not quite ready to create a "three-tier" enterprise level application, you can use this simple approach. If you are using ASP.NET 2.0, then you'll put this code inside your App_Code folder under it's own code file. With this example above you can tap into your needed information all over your site; in your UserControls, MasterPages, ContentPages and anywhere else you may need to."

The Context.Items collection is excellent for passing data from one IHttpModule to another. I think it is quoted in one of the MS ASP.Net books as provided for that purpose.

Maybe easiest is best. That isn't my call.

Cheers


Rgds,
Martin.

For the benefit of all users please mark any post answers as appropriate.
0
mokeefe
5/7/2007 3:12:35 AM

I appreciate your post, and I agree that the long term solution is usually better. Most of my posts in this forum is not what I myself would do, in fact a lot of them I start by saying "I wouldn't do this, nor do i recommend this, but..." The reason I go on with the post though is because people are all at different levels in their programming career (or hobby).

The using of the HttpContext Items, while it may not be the best for all situations, helps new developers to lean away from:

  • Static objects (like old VB "modules" - just bad code)
  • Having to code "content-specific" code such as 'this.Page.FindControl("myUserControl1").FindControl("myDropDownList1").SelectedValue'
  • Or leaning on some other publicly accessable data store (such as the Request.QueryString object) to communicate intra-site.

Coding in the fasion described in that article helps bridge "I'm inside a page" developers to the idea of "I'm inside a site" (or better yet "I'm part of a system") developers. Because the site looks to a single touch point for communication, the developer can soon begin to create a complete solution with DAL, BiLL, Subject and Presentation layers.

Thanks,


-Timothy Khouri
http://www.SingingEels.com/
Developer / Architect / Author
0
Nullable
5/7/2007 11:53:02 AM
Reply:

Similar Artilces:

how do i link two different sitemap with the use of menu control in one .aspx file to two different hyperlink in the master page?
I have two menu control with similar file(eg.defect.aspx) in the master page, whenever i click the similar file(eg.defect.aspx) in either menu control, it will show both the menu control(eg.student menu and staff menu), but i only want to show only either one of the menu (eg,student menu only). Is there any solution to my problem? Am i able to use similar file(eg.defect.aspx) for two different sitemap and two menu control and only show one menu control. Hey, What should or should not be visible; the whole menu, or the selected field?  Are you h...

Accessing two web forms in a single web form
  Hi. I am developing a website in VS 2005 with Ajax & SQL Server. I am having 5 forms in my application. 1) Login Form 2) Main form 3) Form "A" 4) Form "B" I need to show the main form after the User login. I need to show all the contents of form A or form B (Ex: Form "A" user or form "B" user) in the Main Page. Can I show a single page having Main Form controls as well as Form "A" and Form "B" controls? I should access all the controls including Form A/B in the Main Page. Thanks ...

Master Details in two seperate GridView Controls
I am simply trying to have a list of people in the top grid control (works fine), then when selected have the second Grid Control show details for that person(not working). Here is what I am trying from the load event: Sub BindData() Dim myConnection As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionSql")) Dim strPersonSQL, strActSQL As String strPersonSQL = "select row_id, first_name, last_name, middle_initial, dsi_id, created, created_by, program_of_study, email from tbl_person" Dim myPerCommand As New MySqlClient.MySqlComm...

how can i take two sitemapdatasource controls for two sitemap files
Hi, I have 2  web.sitemap files, for 2 diffrent languages, when user login with 1 st langauge mode, i want to display that language menus and  user login with 2  nd langauge mode, i want to display that language menus here i am displaying menus in Master page, -----Her can i take two sitemapdatasource controls for two sitemap files if then how i assign  sitemap files to two diffrent sitemapdatasource controlsadilahmed -----Her can i take two sitemapdatasource controls for two sitemap files or can i take two web.sitemap files   and bind  wi...

testing two three two three two two
Test ...

Compare if two fragments of two xml files are equal (not well-formed)
Is there a way to compare two fragments from two different xml files, that are not well formed using PBDOM functions? P.S. I.E. I divide the file in 3 parts, by doing that, the fragment I want to compare is not going to be well-formed. TRAX wrote: > Is there a way to compare two fragments from two different xml files, that > are not well formed using PBDOM functions? > > > P.S. I.E. I divide the file in 3 parts, by doing that, the fragment I > want to compare is not going to be well-formed. could you do this through file comparison ...

How to control two check boxes in a web form
Hi all, I have two check boxes on a web form, one is pre-configured to checked and the purpose of this is only allow one check box to be checked. The problem is when I click one of them, the other check box status is not controlled by the action, the code behindes are showed bellow. private void chkInternalUser_CheckedChanged(object sender, System.EventArgs e) { if (this.chkInternalUser.Checked) this.chkCustomer.Checked = false; else this.chkCustomer.Checked = true; } private void chkCustomer_CheckedChanged(object sender, System.EventArgs e) { if (this.chkCustomer.Checked ) ...

can I bind two seperate arrays (same size) to two control in item template Datalist
I have a datalist, i want to bind an array in one control - a label.i want to bind another array in another control - a text box, is this possible?they are both of the same length Yes and no.  First of all, you can't have multiple datasources assigned to the same datacontrol like DataList control.  That's the NO part.  The YES part is that you can handle the ItemDataBound event and programmatically set the value of your second control using the e.Item.ItemIndex to retrieve the value from your second array (since they are the same size).  Try it, I think it'll work....

two menu controls required in one aspx page with two different sitemap file
dears,in vs2005 website how it is possible to add two menus with two different sitemaps ??...here i did one menu control like as follows...now this menu is working fine with SiteMapDataSource1  and web.sitemap.now my requirement is i want to add one more menu control with another sitemap file...is it possible to do that way?can anybody help me for this? <asp:Menu ID="Menu1" runat="server" BackColor="Green" BorderColor="Green" BorderStyle="Ridge"              &...

Web form on two web servers
Hi,  Consider a website which is composed of two webforms (for example in two frames) and each one is hosted on a different web server. Is there an easy and secure way to make them share state information with each other? For example, I would like one form to display a picture only if the user can answer a skill testing question in the other form. So form A somehow has to tell form B that it should reload with the picture enabled. I don't want to do it via a cookie on the user's computer, because then the user might be able to fake the cookie and get the picture without answering ...

Using property values of user control between two web forms.
Hi,I am stuck with a problem.I have a user control on more than one web form( say webform1 and webform2 ).The user control consists of several hyperlinks(say hyp1 and hyp2 ).When I enter values in webform1 and then click 'save' button , one of the property of user control (say ID ) is assigned some value. I want to use that value 'ID' in webform2 after the user clicks on hyp2. I dont think using Querystring will be useful because hyp1 is selected be default. It is not a compulsion for the user, that he has to click on hyp2..he can also click on other hyperlinks of the user control also...Ple...

Two UpdatePanels and Two UpdateProgress controls
I have a page with two seperate Update Panels and I would like to have an Update progress Control for each.I have placed each of the respective UpdateProgress controls in the UpdatePanel Template, however when I reload either of the Panels both the UpdateProgress controls are displayed, is there a way to bind the UpdateProgress controls to a single UpdatePanel?RegardsMike From what I saw, I didn't see any mechanisms for associating an UpdateProgress control with any particular UpdatePanel...Anyone else know if I'm wrong, here?Andyhttp://www.fboweb.com   Atlas isn't set up to do tha...

How two make two forms interact each other ???
Hello and thank you for opening my message and tring to help me. Here is my problem : Let we suppose my Power++ project is an application wich consists of two windows; a main window, named FORM_MAIN, and a modeless window, named FORM_SLAVE. FORM_MAIN keeps a command button named BUTT_OPEN which minimizes FORM_MAIN and then creates FORM_SLAVE. FORM_SLAVE keeps instead a command button named BUTT_CLOSE which I want to maximize FORM_MAIN and close FORM_SLAVE. Because FORM_SLAVE is modeless , I cannot maximize FORM_MAIN ( after FORM_SLAVE is closed ) from in...

How to divide a form into two forms, just like as we divide a frame into two frames
 I am very new to this .net and HTML world. I want to break a web page into two sections. In first section I load data in a one column Grid and data elements are hyperlink. Now I want that when I click at that hyperlink, its navigateUrl="image.aspx" should open in the second section of that page. QUESTION:How to break the page(form) into two pages(forms/section)?How to load the coming page(form) into second section?I have some idea of "target"  field but could not use it.I am using ASP.net. I am looking for the detailed answer.  Hi, As far as&n...

Web resources about - Linking two controls in two seperate .ascx files - 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 ...

How effective are parental controls for your child's safety?
... situation. Parents need to find ways to protect their children when they are not around to monitor it themselves. The Use of Parental Controls ...

Kurt Vile, Superchunk, Deer Tick, Waxahatchee, Parquet Courts, Sonic Youth members & more celebrated ...
photos by Amanda Hatfield; words by Bill Pearis Parquet Courts & Lee Ranaldo / Rainer Maria & Meredith Graves / Kurt Vile & Kim Gordon / Waxahatche ...

San Bernardino shooting and the politics of gun control
"It's not enough to keep lamenting these things," Democratic Sen.

Kylie Jenner & her very thin Greyhounds were investigated by Animal Control
... healthy (you can see some screencaps from the Snapchats here ). So… Kylie was investigated by the LA County Department of Animal Care and Control. ...

It is rocket science: Blue Origin control room gets delirious over landing
Technically Incorrect: A new video shows the full raucous glory of the scientific experience. Watch as a packed house celebrates November's successful ...

Hillary Clinton, Bernie Sanders seek gun control reform after shootings
CNN Hillary Clinton, Bernie Sanders seek gun control reform after shootings CNN Washington (CNN) Hillary Clinton and Bernie Sanders said Thursday ...

Even Morning Joe Isn't Buying Carly Fiorina's Gun Control Plan
If you are a Republican Presidential Candidate, the issue of paramount importance, following a gun massacre, is the expression of prayer. 'The ...

Obama Planning To Pull The Trigger On Gun Control Executive Order
Obama Planning To Pull The Trigger On Gun Control Executive Order

Your opinion on gun control doesn't matter
... will die by guns than in car accidents this year. In practice, this is a public health crisis. If you still bristle at the idea of gun control, ...

Resources last updated: 12/4/2015 7:27:07 AM