Showing posts with label masterpage. Show all posts
Showing posts with label masterpage. Show all posts

Wednesday, March 28, 2012

Accessing Masterpage Ajax control from Web user control

Hi all,

I have created a master page in asp2.0 and i have placed ModalPopupExtender in that. I have written a custom Textbox control. In that text Changeded event i have created reference to the Masterpage modalpopupextender using Findcontrrol method. But i cant able to loop through tge Master page controls Properly. I am unable to findthe controls with its client id. Can anybody know how to solv this.

My aim is to call the modalpopupextender show event from the custom control.

<cc1:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="btnForLookup"PopupControlID="LookupPanel"BackgroundCssClass="modalBackground">

Private

Sub AHNLookup_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Click

{ Dim contr as ModalpopupExtender

Contr = Me.page.master.FindControls("ModalPopupExtender1")

Constr.show() -->Gives error as Null object.

}

====

Thanks in advance.

S.Sathishraja

Hi,

Please try to find it in a recursive way.

public?Control FindControlRecursive(Control root, string id)
{
????if (root.ID == id)
????{
????????return root;
????}

????foreach (Control c in root.Controls)
????{
????????Control t = FindControlRecursive(c, id);
????????if (t != null)
????????{
????????????return t;
????????}
????}

????return null;
}
Hope this helps.

Monday, March 26, 2012

Access Updatepanel using masterpage

Hi,

Quick scenario... Simple shop with a masterpage, and thus contentpages. On the masterpage I have an updatepanel which is to act as my basket...

Masterpage:

....

<asp:UpdatePanelID="BasketUpdatePanel"runat="server">

<ContentTemplate>

<asp:TableID="BasketTable"runat="server">

<asp:TableRow>

<asp:TableCell>

<asp:LabelID="BasketHeaderLabel"runat="server"Text="Basket"></asp:Label>

</asp:TableCell>

</asp:TableRow>

<asp:TableRow>

<asp:TableCell>

<asp:Labelrunat="server"Text="0"ID="amountControl"></asp:Label>

</asp:TableCell>

</asp:TableRow>

</asp:Table>

</ContentTemplate>

</asp:UpdatePanel>

.....

On my content page I am dynamically adding items for the shop, and a button to add the item to the basket, this including adding a trigger for each button and adding this to the triggercollection of the updatepanel for my basket..

UpdatePanel basketUpdatePanel = (UpdatePanel)this.Master.FindControl("BasketUpdatePanel");
AsyncPostBackTrigger trigger =newAsyncPostBackTrigger();
trigger.ControlID ="amountControl";
trigger.EventName ="Click";
basketUpdatePanel.Triggers.Add(trigger);

No compilation errors but the following error when the page is rendered:

Control with ID 'amountControl' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.

Help..

Dannv

dannv:

Control with ID 'amountControl' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.

This error means, you can add only controls to the triggercollection they are able to rise an event. A label, like in your situation, could'nt rise any event.


You are rigth, and this of course makes perfectly sense...

I changed the controlid to

trigger.ControlID = basketButton.ID;

Which is the button where the event is fired from...

Clicking the botton, now fires a postback, but does not activate my click method.. any obvious suggestions...??


dannv:

Clicking the botton, now fires a postback, but does not activate my click method.. any obvious suggestions...??

you've the click method assigned as the click event to the button eg. OnClick="basketButton_Click" for serverside handling or OnClientClick="JavaScriptFunction()" for clientside JavaScript?


It is set to serverside handling, using the OnClick event...


dannv:

Clicking the botton, now fires a postback, but does not activate my click method..

Not realy sure what you mean. The workflow should be: the UpdatePanel has basketButtons ClickEvent as a trigger. If the basketButton fire his ClickEvent, the UpdatePanel is triggered and initialize a partial page update from his content. So what you mean with:but does not activate my click method ? Is the updatepanel not updating? get you any error? if so, which error you get?


Sorry for wasting your time on the last issue... just retested and now it works...Devil

But thanks for your help and patience

Dann

Access control on MasterPage from within content page

Hi all,

I have a MasterPage with invisible Label.

In content page I have a few controls and any Button.

When user clicks the Button, the Label on MasterPage appears.

So far - so good.

If I use an UpdatePanel inside the content page, the Label stay invisibleSad.

I know, that it's right behavior for Ajax enabled application, but...

What is the solution?

MasterPage:

<%@dotnet.itags.org. Master Language="C#" AutoEventWireup="true" CodeFile="TestMasterPage.master.cs" Inherits="TestMasterPage" %><!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"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> <asp:Label ID="Label1" runat="server" Text="Error!" Visible="False"/> </form></body></html>

Content page:

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/TestMasterPage.master" AutoEventWireup="true" CodeFile="TestContentPage.aspx.cs" Inherits="TestContentPage" Title="Untitled Page" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem Value="1">Item 1</asp:ListItem> <asp:ListItem Value="2">Item 2</asp:ListItem> <asp:ListItem Value="3">Item 3</asp:ListItem> <asp:ListItem Value="4">Item 4</asp:ListItem> </asp:ListBox> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </ContentTemplate> </asp:UpdatePanel></asp:Content>

Content page code behind:

protected void Button1_Click(object sender, EventArgs e) {//Do something... //... Label lbl = (Label)Page.Master.FindControl("Label1");if (lbl !=null) lbl.Visible =true; }

The solution: enclose the Label on the MasterPage by UpdatePanel:

<%@. Master Language="C#" AutoEventWireup="true" CodeFile="TestMasterPage.master.cs" Inherits="TestMasterPage" %><!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"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"/> <asp:UpdatePanel ID="updatePanel2" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Error!" Visible="False"/> </ContentTemplate> </asp:UpdatePanel> </form></body></html>