Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2006, 02:35 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Panels and defaultbuttons

Imar Spaanjaars from www.spaanjaars.com adviced me to open a topic here so here goes!
I was wondering why I can't set the defaultbutton property of a panel without the error: "The DefaultButton of '-panelname-' must be the ID of a control of type IButtonControl"

I've created a little example to clearify me question:
Code:
<%@ Page Language="VB" MasterPageFile="~/Main.master" Title="Artikels" Theme="CDB_Main" %>

<%@ Register Src="~/UserControls/Datum_Invoer.ascx" TagName="Datum_Invoer" TagPrefix="uc2" %>

<script runat="server">

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub fvNieuwsItems_ItemUpdating(ByVal sender As Object, ByVal e As Web.UI.WebControls.FormViewUpdateEventArgs) _
        Handles fvNieuwsItems.ItemUpdating
        e.NewValues("GebruikersNaam") = User.Identity.Name
    End Sub

    Protected Sub fvNieuwsItems_ItemUpdated(ByVal sender As Object, ByVal e As Web.UI.WebControls.FormViewUpdatedEventArgs) _
        Handles fvNieuwsItems.ItemUpdated
        Response.Write("Updated!")
    End Sub

    Protected Sub fvNieuwsItems_DataBound(ByVal sender As Object, ByVal e As EventArgs) _
        Handles fvNieuwsItems.DataBound
        Dim _fvNieuwsItem As FormView = CType(sender, FormView)
        If _fvNieuwsItem.CurrentMode = FormViewMode.Edit Then
            Dim _btnToFocusOn As Button = CType(_fvNieuwsItem.FindControl("btnUpdate"), Button)
            Me.Panel2.DefaultButton = _btnToFocusOn.ClientID
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Write("testing")
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px" DefaultButton="Button1">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="test" OnClick="Button1_Click" /></asp:Panel>
    <asp:Panel ID="Panel2" runat="server" Height="50px" Width="125px">
        <asp:FormView ID="fvNieuwsItems" runat="server" DataSourceID="odsNieuwsItems" HeaderText="Nieuwsitems op de site" DataKeyNames="NieuwsItemID" Width="520px">
            <EditItemTemplate>
                <table width="540">
                    <tr>
                        <td>
                            <asp:Label ID="lblTitel" runat="server" Text="Titel:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtTitel" runat="server" Text='<%# Bind("Titel") %>' Width="450px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvTitel" runat="server" ControlToValidate="txtTitel"
                                Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="vgInsert"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="revReferentie" runat="server" ControlToValidate="txtTitel"
                                Display="Dynamic" ErrorMessage="Geen HTML-tags toegestaan in dit veld!" ValidationExpression="^[^<>]+$"
                                ValidationGroup="vgInsert"></asp:RegularExpressionValidator></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:Label ID="lblItem" runat="server" Text="Nieuws:"></asp:Label>
                        </td>
                        <td valign="top">
                            <asp:TextBox ID="txtItem" runat="server" MaxLength="4000" Rows="10" Text='<%# Bind("Item") %>'
                                TextMode="MultiLine" Width="450px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvItem" runat="server" ControlToValidate="txtItem"
                                Display="Dynamic" ErrorMessage="RequiredFieldValidator" ValidationGroup="vgInsert"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="revItem" runat="server" ControlToValidate="txtItem"
                                Display="Dynamic" ErrorMessage="Geen HTML-tags toegestaan in dit veld!" ValidationExpression="^[^<>]+$"
                                ValidationGroup="vgInsert"></asp:RegularExpressionValidator></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:Label ID="lblEinddatum" runat="server" Text="Eindigd op:"></asp:Label></td>
                        <td valign="top">
                            <uc2:Datum_Invoer ID="ucEinddatum" runat="server" Required="true" ValidationGroup="vgInsert" Datum='<%# Bind("Einddatum") %>' />
                        </td>
                    </tr>
                </table>
                <asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Update" />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:ImageButton ID="imgEdit" runat="server" CommandName="Edit" ImageAlign="Right"
                    ImageUrl="~/Pics/Edit.gif" />
                <asp:ImageButton ID="imgNew" runat="server" CommandName="New" ImageAlign="Right"
                    ImageUrl="~/Pics/New.gif" /><br />
                <table width="100%">
                    <tr>
                        <td align="right">
                            <asp:Label ID="lblTitel" runat="server" Text="Titel:"></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="lblItmTitel" runat="server" Text='<%# Eval("Titel") %>' SkinID="Bold"></asp:Label></td>
                    </tr>
                    <tr>
                        <td valign="top" style="width: 80px" align="right">
                            <asp:Label ID="lblItem" runat="server" Text="Nieuws:"></asp:Label>
                        </td>
                        <td>
                            <asp:Label ID="lblItmItem" SkinID="FormViewItem" runat="server" Text='<%# QC_Classes.URLtoHyperlink(Eval("Item")) %>'></asp:Label></td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 80px" valign="top">
                            <asp:Label ID="lblEinddatum" runat="server" Text="Eindigd op:"></asp:Label></td>
                        <td>
                            <asp:Label ID="lblItmEinddatum" SkinID="FormViewItem" runat="server" Text='<%# Eval("Einddatum", "{0:D}") %>'></asp:Label></td>
                    </tr>
                </table>
            </ItemTemplate>
            <EmptyDataTemplate>
                Selecteer een nieuwsitem om zijn details hier te zien of maak een nieuw item aan
                door op de knop hieronder te klikken.<br />
                <asp:ImageButton ID="imgNew" runat="server" CommandName="New" ImageUrl="~/Pics/New.gif" />
            </EmptyDataTemplate>
        </asp:FormView>
        <asp:ObjectDataSource ID="odsNieuwsItems" runat="server" InsertMethod="INSERT" SelectMethod="SELECT_ONE"
            TypeName="Business_Objects.Site_NieuwsItemsLogic" UpdateMethod="UPDATE" OldValuesParameterFormatString="original_{0}">
            <UpdateParameters>
                <asp:Parameter Name="nieuwsItemID" Type="Int32" />
                <asp:Parameter Name="gebruikersNaam" Type="String" />
                <asp:Parameter Name="item" Type="String" />
                <asp:Parameter Name="titel" Type="String" />
                <asp:Parameter Name="einddatum" Type="DateTime" />
           </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="datumGepost" Type="DateTime" />
                <asp:Parameter Name="gebruikersNaam" Type="String" />
                <asp:Parameter Name="item" Type="String" />
                <asp:Parameter Name="titel" Type="String" />
                <asp:Parameter Name="einddatum" Type="DateTime" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter DefaultValue="0" Name="nieuwsItemID" QueryStringField="nieuwsid"
                    Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FooterContent" Runat="Server">
</asp:Content>
This should be right, right

 
Old June 12th, 2006, 01:57 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Sensei_D,

Would it be possible to create a simple but reproducible scenario for this?

The code you posted is impossible to test, as it depends on external user controls and business logic that we don't have...

Imar


 
Old June 13th, 2006, 02:02 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi Sensei_D,

Would it be possible to create a simple but reproducible scenario for this?

The code you posted is impossible to test, as it depends on external user controls and business logic that we don't have...

Imar


It's hard to create a small example without connecting to my database which you don't have, but the idea is really simple. Let me try to explain a way to create a simple example;
- Create 2 panels
- Place something in panel 1 with a button and set that as defaultbutton
- Place a Formview in panel 2
- Bind the formview to some source
- Put the Formview in update-mode
- Make sure the Formview contains a update button

Now, the part that doesn't work for me is making the updatebutton inside the Formview the defaultbutton of panel2

Otherwise maybe you could give me an example which works for you, so I can test it...



 
Old June 13th, 2006, 01:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I could make it work by using UniqueID, as suggested in my article, but only in a normal ASPX page.

As soon as I moved the code to a Master Page, things broke down and I got the same error you got.

Not sure why we're getting this error though; haven't found a solution yet...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old June 15th, 2006, 05:55 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 I could make it work by using UniqueID, as suggested in my article, but only in a normal ASPX page.

As soon as I moved the code to a Master Page, things broke down and I got the same error you got.

Not sure why we're getting this error though; haven't found a solution yet...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Aw, thats too bad. Thnx for trying tho. I did fix it with javascript, but it would have been nicer with asp.net ofcourse.

 
Old July 3rd, 2006, 09:39 AM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh my, you would have thought M$ would have made this a bit easier. I've spent the last 4 hours :( trying to get this to work & I've ended up here :)

Quote:
quote:Originally posted by Sensei_D
 Aw, thats too bad. Thnx for trying tho. I did fix it with javascript, but it would have been nicer with asp.net ofcourse.


Could Sensei_D (or some other kind soul) please point me to how this can be done in JavaScript?

 
Old July 3rd, 2006, 10:50 AM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've managed to do it after reading this:

http://codebetter.com/blogs/darrell....3/03/8374.aspx

GL

 
Old July 11th, 2007, 12:36 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there's a solution for this problem?

Or even simpler : How can I make this code work in a user control inside a masterpage ?

User Control :

<asp:Panel ID="i_pnlFvInformations" runat="server" BorderColor="#ff0000" BorderStyle="Solid" BorderWidth="2px">
    <br />
    <br />
    <br />
    <br />
    <asp:Label ID="i_lbl" runat="server"></asp:Label>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <br />
    <br />
    <br />
    <br />
</asp:Panel>
<asp:Panel ID="i_pnlFvInformations2" runat="server" BorderColor="#ff0000" BorderStyle="Solid" BorderWidth="2px">
    <br />
    <br />
    <br />
    <br />
    <asp:Label ID="i_lbl2" runat="server"></asp:Label>
    <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
    <br />
    <br />
    <br />
    <br />
</asp:Panel>

Code Behind :

    protected void Page_Load(object sender, EventArgs e)
    {
        i_pnlFvInformations.DefaultButton = Button1.UniqueID;
        i_pnlFvInformations2.DefaultButton = Button2.UniqueID;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        i_lbl.Text = "test1";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        i_lbl2.Text = "test2";
    }

Using this code I have the error (in french) : Le DefaultButton de 'i_pnlFvInformations' doit être l'ID d'un contrôle de type IButtonControl.

Can anyone help to set the DefaultButton of a panel at runtime?

Thanks in advance.

 
Old July 12th, 2007, 08:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Would you be so kind as to tell us what that error message says in English?

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Raised Panels HotBlue Visual Basic 2005 Basics 0 October 20th, 2006 03:42 PM
GridLayout and Panels spudgun2005 J2EE 0 September 12th, 2005 01:21 AM
Staus Bar Panels Text Value(VB.NET) narendra_patil VS.NET 2002/2003 0 April 22nd, 2005 07:32 AM
explorer like panels in VB 6.0 madhukp Pro VB 6 2 September 10th, 2004 11:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.