This one has me a bit confused and I'm not finding what I
need in the MSDN or by searching these forums, so here
goes...
I have a rather large, complex code-in-page WebForm
(don't ask) and a section of that Form is 4 or 5
ASP:Panels pretending to be a set of Tabs, each with its
own section of the form.
In order to simplify managing this page, since code-
behind is not an option (don't ask, not my fault), I
thought I had the solution...
I would convert each Panel into a User Control.
The problem is that the panels usually depend on at least
one Form Control from at least one other Panel.
I already know about RaiseBubbleEven t() and OnBubbleEvent
() and have used them elsewhere, but they only work going
UP the container heirarchy.
I need to :
1 - (partially) handle an event in the UserControls
(panels), then (partially handle the same event in
ANOTHER UserControl(pan el) on the same form/page.
2 - handle an event in a UserControl(pan el) BUT be able
to retrieve values from form fields(Controls ) in OTHER
UserControls(pa nels) to help determine how to handle the
event.
3 - (partially) handle an event in the Form(aspx)
depending on values of form controls in the UserControls
4 - manipulate values of form controls in the
UserControls
Like I said, I already know how to Bubble events, but
that only goes up.
The part I am missing is how to "Elbbub" events (bubble,
backwards) or manipulate data in child objects.
The trick is, this is all Code-in-Page and nothing will
convince those in control to return to Code Behind.
Anyone know how to do what I want/need to do?
I have a set of aspx/ascx pages that I can email or ftp
for anyone interested. 6 6648
Not sure what you mean by "codebehind is not an option." It SOUNDS like what
you mean is that compiled CodeBehind DLLs are not an option. You can still
use CodeBehind, just put it in the same file as the Page Template. You can
put it right at the top of the Page, in a "runat=serv er" script. Example:
<%@ Page language="C#" %>
<script runat="server" >
public void Page_Load()
{
// Page_Load code goes here
}
</script>
<html>
....Page Template HTML and Code Goes here
</html>
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer http://www.takempis.com
Complex things are made up of
lots of simple things.
"Tom Rowton" <to*******@hotm ail.com> wrote in message
news:0a******** *************** *****@phx.gbl.. . This one has me a bit confused and I'm not finding what I need in the MSDN or by searching these forums, so here goes...
I have a rather large, complex code-in-page WebForm (don't ask) and a section of that Form is 4 or 5 ASP:Panels pretending to be a set of Tabs, each with its own section of the form.
In order to simplify managing this page, since code- behind is not an option (don't ask, not my fault), I thought I had the solution...
I would convert each Panel into a User Control. The problem is that the panels usually depend on at least one Form Control from at least one other Panel.
I already know about RaiseBubbleEven t() and OnBubbleEvent () and have used them elsewhere, but they only work going UP the container heirarchy.
I need to : 1 - (partially) handle an event in the UserControls (panels), then (partially handle the same event in ANOTHER UserControl(pan el) on the same form/page.
2 - handle an event in a UserControl(pan el) BUT be able to retrieve values from form fields(Controls ) in OTHER UserControls(pa nels) to help determine how to handle the event.
3 - (partially) handle an event in the Form(aspx) depending on values of form controls in the UserControls
4 - manipulate values of form controls in the UserControls
Like I said, I already know how to Bubble events, but that only goes up. The part I am missing is how to "Elbbub" events (bubble, backwards) or manipulate data in child objects.
The trick is, this is all Code-in-Page and nothing will convince those in control to return to Code Behind.
Anyone know how to do what I want/need to do?
I have a set of aspx/ascx pages that I can email or ftp for anyone interested.
>Not sure what you mean by "codebehind is not an
option."
By "code-behind", I am referring to the "strict"
definition of code-behind, i.e. a two-file page - *.as*x
+ *.as*x.vb.
I am using single-file or code-in-page pages, similar to
old-style ASP 3.0.
It sounds like maybe you know how to do this with
the "normal" MS-promoted code-behind setup, so if this is
easily converted to a single-file, code-in-page page,
please share the love. ;) I've found plenty of articles
on how to get/set values in User Controls from a page
that contains them using code-behind, but nothing about
doing this from one user control to another with single-
file pages.
I've been banging on this for two days now and can't seem
to retrieve info from one user control with code in
another without Bubbling the event to the parent page
(which works fine, but will only further complicate the
code).
Hi Tom,
I already DID "share the love," but apparently you didn't notice. Let me
reproduce it for you:
<%@ Page language="C#" %>
<script runat="server" >
public void Page_Load()
{
// Page_Load code goes here
}
</script>
<html>
....Page Template HTML and Code Goes here
</html>
Note the server-side script at the top. All you need to do is put the code
that would normally go in the CodeBehind class definition in a separate file
inside the CodeBehind script at the top of the page. I've already added the
Page_Load script as an example.
You definitely DON'T want to try programming ASP./Net with the old ASP
style. It's not designed for that, and will cause you beaucoups trouble if
you try to work with this Object-Oriented technology in a procedural way.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer http://www.takempis.com
Complex things are made up of
lots of simple things.
"Tom Rowton" <to*******@hotm ail.com> wrote in message
news:00******** *************** *****@phx.gbl.. . Not sure what you mean by "codebehind is not an option."
By "code-behind", I am referring to the "strict" definition of code-behind, i.e. a two-file page - *.as*x + *.as*x.vb.
I am using single-file or code-in-page pages, similar to old-style ASP 3.0.
It sounds like maybe you know how to do this with the "normal" MS-promoted code-behind setup, so if this is easily converted to a single-file, code-in-page page, please share the love. ;) I've found plenty of articles on how to get/set values in User Controls from a page that contains them using code-behind, but nothing about doing this from one user control to another with single- file pages.
I've been banging on this for two days now and can't seem to retrieve info from one user control with code in another without Bubbling the event to the parent page (which works fine, but will only further complicate the code).
Hi Tom,
Yes, post your sample code. I, for one, am having a hard time understanding
the exact nature of the problem.
I understand your confusion re my use of the term "CodeBehind ." There are a
number of different configurations for implementing what is often referred
to as "CodeBehind code," and this has a tendancy to muddy the water when
discussing how to implement the Class code that completes the Page Template
code. Taken literally, "CodeBehind " does refer to a separate file. I (and
some others) tend to use the term to talk about the "Code Behind the Page,"
which, of course, can be in a separate file or in the same file as the Page
Template (as we've been discussing). In terms of functionality and
optimization, it makes very littel difference whether you use a separate
file, DLLs, or just a single file with the Page Template and Page Class Code
in it.
The most important point, which you seem to understand, is that the code in
the Page Template (between the <html> and </html> tags) have as little
executable code in it as possible, and that you do your manipulation of the
Page through the CodeBehind Class. And I wouldn't be embarrassed to say that
I was including the "CodeBehind " code in the same file as the Page Template.
That is perfectly legitimate. I believe that Microsoft is considering taking
a similar approach in the future with the next version of ASP.Net. It
doesn't necessarily make sense to have ALL of the Pages in a project
compiled into a single DLL, especially when the first request for the page
results in the code being compiled and cached.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer http://www.takempis.com
Complex things are made up of
lots of simple things.
"Tom Rowton" <to*******@hotm ail.com> wrote in message
news:0c******** *************** *****@phx.gbl.. . I already DID "share the love," but apparently you Ahh, I had to view source, as I've viewing this via msdn.microsoft. com, so your asp tags disappeared.
What you describe is basically what I'm doing - code AND html in the same file, as opposed to a separate code- behind file with an HTML file.
I have no say in how this thing is built, so I have to work with it the way it is - single-file webform.
I have an example that shows how I am failing to do what I want, does it make sense to post them in my message?
Thanks for your help so far, I think I just was unclear about meaning _separate_ code-behind files when I said "code-behind".
Okay, let me see if I understand you correctly. You've got an Event Handler
for one UserControl that needs to do something with another UserControl,
right? It looks to me like your error is in using Page.FindContro l(...). The
FindControl() method of a Control looks for controls in that Control's
Controls Collection (was that a confusing sentence or what?). Your
UserControls are not in the Page's Controls Collection; they are in your
Form's Controls collection. Does that help?
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer http://www.takempis.com
Complex things are made up of
lots of simple things.
"Tom Rowton" <to*******@hotm ail.com> wrote in message
news:6b******** *************** *****@phx.gbl.. . Ok, I hope this works. I'll just post entire files, and separate them by a line of dashes. MyCaseSub.ascx was trying to get the value of MyCaseMain.ascx 's label, but it wouldn't work. I could get the ID of the Case:MainPanel usercontrol, but I can't access the Property Method _UNLESS_ I bubble the event to MyCase.aspx and let MyCase.aspx call the Get.
Clearly, this is a matter of not understanding the object model, but I can't seem to find anyone to tell me how to do it without Bubbling, or I'm asking in an unclear manner.
TIA, Tom
MyCase.aspx ------------------------ <%@ Register TagPrefix="Case " TagName="MainPa nel" Src="MyCaseMain .ascx" %> <%@ Register TagPrefix="Case " TagName="SubPan el" Src="MyCaseSub. ascx" %> <%@ Register TagPrefix="Case " TagName="SubPan el2" Src="MyCaseSub2 .ascx" %> <%@ Import Namespace = "System.Web.UI. WebControls" %> <%@ Import Namespace = "System.Data.Sq lTypes" %> <%@ Import Namespace = "System.Data.Sq lClient" %> <%@ Import Namespace = "System.Drawing " %> <%@ Import Namespace = "System.Dat a" %> <%@ Import Namespace = "System.Web " %> <%@ Import Namespace = "System" %> <%@ Page Language="vb" Inherits="Syste m.Web.UI.Page" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>User Controls Test Page</title> <script language="VB" runat="server">
Protected Overrides Function OnBubbleEvent(B yVal source As Object, ByVal args As System.EventArg s) As Boolean If source.GetType. Equals (GetType (Button)) Then Dim oButton As Button = source Select Case oButton.ID Case "btnMainBut ton" 'Change text of Subsection Label
SubPanel1.SubLa belValue = "Changed by Main Panel via RaiseBubbleEven t()" Case "btnSubButt on" 'Change text of Main Label
MainPanel1.Main LabelValue = "Changed by Sub Panel via RaiseBubbleEven t()" Case "btnGetMain " dim temp as string = MainPanel1.Main LabelValue
SubPanel1.lblPa rentValue = temp Case "btnSub2But ton" 'Change text of Main Label and Subsection Label
SubPanel1.SubLa belValue = "**Changed by Sub2 Panel via RaiseBubbleEven t()**"
MainPanel1.Main LabelValue = "**Changed by Sub2 Panel via RaiseBubbleEven t()**" End Select End If End Function
sub btnReset_Click( sender as Object, e as EventArgs) SubPanel1.SubLa belValue = "Sub Panel" SubPanelB1.Sub2 LabelValue = "Sub2 Panel" MainPanel1.Main LabelValue = "Main Panel" end sub
Sub CaseTabBtn_Clic k(sender As Object, e As System.EventArg s) ' CasePanel.Visib le = True ' AssignmentPanel .Visible = False end sub Sub AssignmentTabBt n_Click(sender As Object, e As System.EventArg s) ' CasePanel.Visib le = False ' AssignmentPanel .Visible = True end sub sub page_load(sende r As Object, e As System.EventArg s) if not page.ispostback end if end sub </script> <META content="True" name="vs_showGr id"> <META content="Micros oft Visual Studio.NET 7.0" name="GENERATOR "> <META content="Visual Basic 7.0" name="CODE_LANG UAGE"> <META content="JavaSc ript" name="vs_defaul tClientScript"> <META content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema"> </HEAD> <body runat=server> <FORM id="Form1" method="post" encType="multip art/form-data" runat="server"> <asp:literal id="litScript" runat="server" EnableViewState ="False"></asp:literal> <asp:panel id="MainPanel" runat="server" borderwidth="1" borderstyle="ri dge" backcolor="Pale Goldenrod" HorizontalAlign ="Center">  ; <CASE:MainPan el id="MainPanel1 " runat="server" NAME="MainPanel 1"></CASE:MainPanel> </asp:panel> <P></P>
<asp:linkbutt on id="CaseTabBtn " onclick="CaseTa bBtn_Click" runat="server" BackColor="Whit e" BorderWidth="1" BorderColor="Go ldenrod">Case</asp:linkbutton> <asp:linkbutt on id="AssignmentT abBtn" onclick="Assign mentTabBtn_Clic k" runat="server" BackColor="Whit e" BorderWidth="1" BorderColor="Go ldenrod">Assign ment</asp:linkbutton> & nbsp;
<asp:panel id="CasePanel" runat="server" borderwidth="1" borderstyle="ri dge" backcolor="Pale Goldenrod" HorizontalAlign ="Center">  ; <CASE:SubPane l id="SubPanel1" runat="server" NAME="SubPanel1 "></CASE:SubPanel> </asp:panel>
<asp:panel id="AssignmentP anel" runat="server" borderwidth="1" borderstyle="ri dge" backcolor="Pale Goldenrod" HorizontalAlign ="Center">  ; <CASE:SubPane l2 id="SubPanelB1 " runat="server" NAME="SubPanelB 1"></CASE:SubPanel2> </asp:panel> <asp:button id="btnReset" onclick="btnRes et_Click" runat="server" Text="Reset all Panels"></asp:button> </FORM> </BODY> </HTML>
---------------------- MyCaseMain.ascx ---------------------- <%@ Control Language="vb" AutoEventWireup ="false" Inherits="Syste m.Web.UI.UserCo ntrol"%> <%@ Import Namespace = "System.Web.UI. WebControls" %> <%@ Import Namespace = "System.Data.Sq lClient" %> <%@ Import Namespace = "System.Drawing " %> <%@ Import Namespace = "System.Dat a" %> <%@ Import Namespace = "System.Web " %> <%@ Import Namespace = "System" %> <script language="VB" runat="server"> Property MainLabelValue( ) as String Get Return lblMainLabel.Te xt end Get Set lblMainLabel.Te xt = value end Set end Property sub btnMainButton_C lick(sender as Object, e as EventArgs) RaiseBubbleEven t(sender, e) end sub </script> <hr> Main Section<BR> <asp:Label id="lblMainLabe l" runat="server" Visible="True"> Main Label(MyCaseMai n.ASCX) </asp:Label><BR>< BR> <asp:button id="btnMainButt on" onclick="btnMai nButton_Click" runat="server" Text="Change Subsection Panel"></asp:button> <hr>
----------------- MyCaseSub.ascx -----------------
<%@ Control Language="vb" AutoEventWireup ="false" %> <%@ Import Namespace = "System.Web.UI. WebControls" %> <%@ Import Namespace = "System.Data.Sq lClient" %> <%@ Import Namespace = "System.Drawing " %> <%@ Import Namespace = "System.Dat a" %> <%@ Import Namespace = "System.Web " %> <%@ Import Namespace = "System" %> <script language="VB" runat="server"> Property SubLabelValue() as String Get Return lblSubLabel.Tex t end Get Set lblSubLabel.Tex t = value end Set end Property Property lblParentValue( ) as String Get Return lblParent.Text end Get Set lblParent.Text = value end Set end Property sub btnSubButton_Cl ick(sender as Object, e as EventArgs) RaiseBubbleEven t(sender, e) end sub sub btnGetMain_Clic k(sender as Object, e as EventArgs) RaiseBubbleEven t (sender, e) ' Dim MyControl as Control = Page.FindContro l("MainPanel1 ") ' if (not MyControl is Nothing) then ' lblParent.Text = MyControl.MainL abelValue() ' else ' lblParent.Text = "MainPanel1 not found" ' end if end sub </script> <hr> Sub Section<BR> <asp:Label id="lblSubLabel " runat="server" Visible="True"> Sub Label(MyCaseSub .ASCX)</asp:Label><BR> Main Panel's ID:<asp:Label id="lblParent" runat="server" Visible="True"> </asp:Label><BR> <asp:button id="btnSubButto n" onclick="btnSub Button_Click" runat="server" Text="Change Main section Panel"></asp:button> <asp:button id="btnGetMain " onclick="btnGet Main_Click" runat="server" Text="Get Main Panel label"></asp:button> <hr>
--------------
>Form's Controls collection. Does that help?
It's good info to have, but doesn't really fix my
problem.
in MyCaseSub.ascx where I have commented out
---------------------------------------------
Dim MyControl as Control =
Page.FindContro l("MainPanel1 ")
if (not MyControl is Nothing) then
lblParent.Text =
MyControl.MainL abelValue()
else
lblParent.Text = "MainPanel1 not
found"
end if
------------------------------------------------
The "else" never happens.
MyControl is _never_ Nothing.
I can print the ID out just fine.
But I am unable to access the "MainLabelValue ()" Property
GET - which works just fine from the bubbled event in
MyCase.aspx.
To sum up, I know that Page.FindContro l() finds the
usercontrol, because I can print out the ID I've given it
in the HTML, but I cannot access the Property I've given
in the script block of the UserControl.
Or did I just misunderstand your point? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kristian Nybo |
last post by:
Hi,
I'm writing a simple image file exporter as part of a school project. To
implement my image format of choice I need to work with big-endian
bytes, where 'byte' of course means '8 bits', not 'sizeof(char)'. It
seems that I could use bitset<8> to represent a byte in my code --- if
you have a better suggestion, I welcome it --- but that...
|
by: Barb Alderton |
last post by:
I am working with SharePoint 2003. I am using an existing webpart as a
child control (server control). I need to access/manipulate the HTML that
the control outputs prior to rendering it to the the page. The control
outputs a list in a one-column table format. I need to access the contents
of the rows and output them with restrictions in...
|
by: Søren M. Olesen |
last post by:
How do I manipulate a control in one frame from another frame ??
I've tried something like:
Class1
TextBox.Text="Text1"
Session("TextBox")=TextBox1
Class2
|
by: martin |
last post by:
Hi,
I am a web page and a web user control. My web user control is placed in my
web page using the following directive
<%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx"
%>
The web user control contains the following server controls
|
by: Shourie |
last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.
1) MainPage_load
2) User control1_Load
user clicks a dropdown in UC1
_________________________
1) MainPage_Load
2) User Control_1 Load
| |
by: John Smith |
last post by:
I still have not gotten this damn thing figured out and I'm asking for help
one last time before I give up on it. I have a user control that contains a
paged gridview control. The master page contains a menu control What I
want to happen is that, whenever a menu item is selected, the appropriate
user control will load. Simple enough? ...
|
by: Rob |
last post by:
I've created an application which is intended to allow users to draw a
diagram of a network - with workstations, servers, switches, links (all
devices in my language) etc. I've created a user control made up of a
picturebox and a textbox (to allow the user to enter a name). When a user
wants to add a 'device' to the background surface (in my...
|
by: Ken Fine |
last post by:
I'm interested in programmatically manipulating groups of ASP.NET controls
by type. Can someone suggest code for the following?
Loop through, say, all label controls on a page, and assigning a CssClass to
them, or programmatically making the Visible/not Visible.
If applied to a containing page, such a function would traverse all user...
|
by: David Hearn |
last post by:
I have a user control that is embedded into a <DIVtag in my aspx page. The
div tags visibility is set to true from the page when the user clicks on an
image. There is a user control within the div and I would like to hide (set
the visibility) the div once the user selects a date in the calendar that is
part of the user control. The div on the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |