CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 4/17/2007 2:18:43 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 11 Views: 45 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
12 Items, 1 Pages 1 |< << Go >> >|
eusebiu
Asp.Net User
Access to a label control into a Master Page4/17/2007 2:18:43 PM

0/0

Hello...

I have a masterpage that has a page as it`s content and a label. On the page I have a button where aI throw an exception. I want to write the exception message into the the masterpage`s label.

I've tried this mehods:

1.(Page.Master.FindControl("Label1") as Label).Text = ex.Message;

2.ClientScript.RegisterClientScriptBlock(this.GetType(), "11", "<script language='javascript' type='text/javascript'>document.getElementById('ctl00_Label1').innerText=" + ex.Message + ";</script>");

the code is in the catch(Exception ex) block.

Thanks

Benners_J
Asp.Net User
Re: Access to a label control into a Master Page4/17/2007 4:13:58 PM

0/0

What happens with the first example you tried?  This worked for me.  It just throws an exception, and then sets the text of Label1 to exception's text.

protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            throw new Exception("Testing");
        }
        catch (Exception ex)
        {
            (Page.Master.FindControl("Label1") as Label).Text = ex.Message;
        }
    }
 
eusebiu
Asp.Net User
Re: Access to a label control into a Master Page4/17/2007 5:29:02 PM

0/0

OK... try puting the label into a usercontrol :)

I am 100% sure that will not work...

Benners_J
Asp.Net User
Re: Access to a label control into a Master Page4/17/2007 5:36:38 PM

0/0

eusebiu:

OK... try puting the label into a usercontrol :)

I am 100% sure that will not work...

Yup, that makes a difference.  Smile

You should be able to get to it through your user control.  Something along the lines of the following:

((Page.Master.FindControl("WebUserControl1") as Control).FindControl("Label1") as Label).Text = ex.Message;

eusebiu
Asp.Net User
Re: Access to a label control into a Master Page4/18/2007 2:55:55 PM

0/0

I found my problem....

It enters twice in MasterPage's Page_Load method... how can I find all Load events?

Benners_J
Asp.Net User
Re: Access to a label control into a Master Page4/18/2007 4:34:14 PM

0/0

I'm more used to how VB handles events.  Hopefully someone else will have a better understanding of this, but here are my thoughts.  For what it's worth:

The code that initializes all the controls that you make in the designer and adds the event handlers doesn't get created until runtime, so I don't think there is a way to view or change that.  You can turn "AutoEventWireup" off in the page directive for the MasterPage and then explicitly register for the On_Load event.  You can put onload="Page_Load" in the page's form tag to do that.  That may make a difference.  Also, if you have AutoEventWireup turned on, make sure you aren't assigning the Page_Load event anywhere else.

Sorry I can't be more help with this.  Hopefully someone else will be able to give you more info.

eusebiu
Asp.Net User
Re: Access to a label control into a Master Page4/19/2007 11:50:13 AM

0/0

I`ve really got it now.. :)

I`ve put the Button the causes the exeception into an UpdatePanel control. I think that the MasterPage's Label is loaded with "" Text and, because the exeception comes later, it didn`t write the exeption  message in the Label because is not on the same thread  with Response(because of the UpdatePanel)... Am I right? If I`m right... how can I solve this problem?

Thanks!

Benners_J
Asp.Net User
Re: Access to a label control into a Master Page4/19/2007 3:12:32 PM

0/0

I don't think that having the button in the UpdatePanel would cause a problem,l though I'm not certain.  Could you post the code for your aspx and code-behind pages (at least enough to recreate the error)?
eusebiu
Asp.Net User
Re: Access to a label control into a Master Page4/20/2007 9:20:06 AM

0/0

Sure...

MasterPage: 

<%

@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

html xmlns="http://www.w3.org/1999/xhtml" >

<

head runat="server">

<title>Untitled Page</title>

 

</

head>

<

body>

<form id="form1" runat="server">

<div>

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>

<asp:Label runat="server" ID="Label1" />

</div>

</form>

</

body>

</

html>

Page:

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"

MasterPageFile="~/MasterPage.master" %>

<

asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:UpdatePanel runat="server" ID="UpdatePanel">

<ContentTemplate>

<asp:Button ID="but1" Text="Button" runat="server" OnClick="but1_Click" />

<asp:UpdateProgress ID="UpdateProgress1" runat="server">

<ProgressTemplate>

<div class="progress">

<img src="indicator.gif" alt="Updating..." />Updating...</div>

</ProgressTemplate>

</asp:UpdateProgress>

</ContentTemplate>

</asp:UpdatePanel>

</

asp:Content>

Button1_Click method

protected

void but1_Click(object sender, EventArgs e)

{

try

{

throw new Exception("Testing");

}

catch (Exception ex)

{

(Page.Master.FindControl(

"Label1") as Label).Text = ex.Message;

}

}

bpag
Asp.Net User
Re: Access to a label control into a Master Page4/20/2007 1:16:26 PM

0/0

Your problem is that your button is in an updatepanel so when you click it it posts back, throws the exception and sets the label text but you'll never see the updated label text because the only part of the page that gets updated is the stuff inside the update panel and the label is outside the update panel. So you'll never see the label updated this way.
If this post answered your question please remember to 'Mark as Answer'!
eusebiu
Asp.Net User
Re: Access to a label control into a Master Page4/23/2007 7:58:06 AM

0/0

OK... I understand now...  I moved the button outside the updatepanel and now it works fine. But inside the update panel I have an updateprogress. How can I start this update progress? When the button was inside the updatepanel, the updateprogress worked fine.

Thanks

Zhao Ji Ma - MS
Asp.Net User
Re: Access to a label control into a Master Page4/23/2007 2:13:19 PM

0/0

Hi,

The following Url has samples on associating an UpdateProgress Control with an UpdatePanel Control. Hope it helps.

http://ajax.asp.net/docs/overview/UpdateProgressOverview.aspx


Zhao Ji Ma
Sincerely,
Microsoft Online Community Support

?Please remember to click ?Mark as Answer? on the post that helps you, and to click ?Unmark as Answer? if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ?
12 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Pro ASP.NET 2.0 Website Programming Authors: Damon Armstrong, Pages: 641, Published: 2005
Pro ASP.NET 2.0 in VB 2005: From Professional to Expert Authors: Laurence Moroney, Matthew MacDonald, Pages: 1253, Published: 2006
Pro ASP.NET 3.5 in C# 2008 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1498, Published: 2007
Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages Authors: Jacob J. Sanford, Pages: 474, Published: 2007
ASP.NET 2.0 Black Book: black book Authors: Dreamtech Software, Dreamtech Software, Charul Shukla, Anil Kumar Barnwal, Dreamtech Software India, Pages: 1167, Published: 2006
Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter Kit: visual web developer 2005 express edition starter kit Authors: David Sussman, Alex Homer, Pages: 312, Published: 2005
ASP.NET 3.5 For Dummies Authors: Ken Cox, Pages: 404, Published: 2008
Special Edition Using Microsoft FrontPage 2002 Authors: Neil Randall, Dennis Jones, Pages: 914, Published: 2001
Learning ASP.NET 3.5 Authors: Jesse Liberty, Dan Hurwitz, Brian MacDonald, Pages: 576, Published: 2008
Office 2001 for Macintosh: The Missing Manual Authors: Nan Barber, David Reynolds, Pages: 637, Published: 2001

Web:
Can't access label in MasterPage Talk about Can't access label in MasterPage. ... When the page is rendered, the label control emits a span in the HTML ...
Working with ASP.NET Master Pages Programmatically However, you can use the FindControl method to locate specific controls on the master page. If the control that you want to access is inside a ...
Master Pages - Strongly-Typed control access I can access *properties* on the Master Page in a strongly typed way, ..... public variable to expose a Label control on the master page): ...
Less Than Dot - Wiki - ASP.NET: Access Master Page controls from ... To demonstrate how we create and use these Properties, imagine we have a Master Page which contains a Label control (we'll just call it "Label1"), ...
Masterpage and Label control? How can I reach the label control on the master page from other ... "Master" property into the exact type of the master page and access any ...
need help accessing label value from master page into the content ... I have lovem master page file and lovec content page. I'm assigning some text to labelm control in master page and trying to access the same ...
Master Pages, Themes, and Control Skins reaches up into the Master Page to look for controls. For example, if you have a Label control. defined on your Master Page named lblTitle, ...
how to put text in label in masterpage? - ASP.NET Forums Can you tell me how to access the label in the master page itself? ... You could have problmes if your label within another control or in ...
Accesing a label control on masterpage from sub page - ASP Free I would like to be able to access the text property of the label control which is on my master page from my sub master page. ...
MasterPage Class (System.Web.UI) You identify the ContentPlaceHolder control of a master page that a Content control is ... To access controls, properties, and functions of the master page, ...

Videos:
Long Beach City Council Meeting Long Beach City Council Meeting




Search This Site:










can't use sql 2005 express db online.....help me pleasee

sitemapnode title

sending email in html or text

cannot create an abstract class

theme with columns in gridview

problem running asp.net

'dataitem' is not a member of 'system.web.ui.control'

need help with skin's problem.

can some one show me a example that search a sql database and use a table to show all results?

any regular expression experts here?

required sql server permissions

conditional login????

how do i copy users, roles, membership and so on from one web server to another?

incordia smartsite

administrator's guide

unhandled error loading module

to get checkboxes in a datagrid to appear checked upon pageload

trusted connections and forms security

vb code

content management questions

fancy a session?

mainmenu component invisible in toolbox

asp.net configuration

same problem here too

portal alternatives ???

using system.directoryservices in backcode??

creating excel chart from asp

2.1.2 cant create portal

taking requests for sigmapro outlook tasks and new module - dnn outlook contacts

skinning

 
All Times Are GMT