Hi, im having a problem with a custom control in asp.net

I've googled but I cant find any solution, maybe the people here can lend me a hand.

Here's the code

public Table generateControls(GeoData geodata)

        {

            Table table = new Table();

            Label StrAddress = new Label();

            Label Localty = new Label();

            Label Country = new Label();

            ImageButton Locate = new ImageButton();

            ImageButton Accept = new ImageButton();

 

            //Asigno los valores a los controles

            Locate.ImageUrl = "/Img/icon-map.png";

            Locate.ImageAlign = ImageAlign.AbsMiddle;

            Locate.Height = 32;

            Locate.Width = 32;

            Locate.CommandArgument = System.Guid.NewGuid().ToString();

            Locate.ID = System.Guid.NewGuid().ToString();

            Locate.Click += new ImageClickEventHandler(Locate_Click);

            Locate.PostBackUrl = "default.aspx";

 

            Accept.ImageUrl = "/Img/big_green_tick_icon.png";

            Accept.ImageAlign = ImageAlign.AbsMiddle;

            Accept.Height = 32;

            Accept.Width = 32;

 

            string[] data = geodata.Address.Split(',');

 

            if (data.Length == 5)

            {

                StrAddress.Text = "<b>Direccion:</b> " + data[0];

                Localty.Text = "<b>Localidad:</b> " + data[1] + ", " + data[2] + ", " + data[3];

                Country.Text = "<b>Pais:</b> " + data[4];

            }

            else if (data.Length == 4)

            {

                StrAddress.Text = "<b>Direccion:</b> " + data[0];

                Localty.Text = "<b>Localidad:</b> " + data[1] + ", " + data[2];

                Country.Text = "<b>Pais:</b> " + data[3];

            }

            else

            {

                StrAddress.Text = "<b>Direccion:</b> " + data[0];

                Localty.Text = "<b>Localidad:</b> " + data[1];

                Country.Text = "<b>Pais:</b> " + data[2];

            }

 

            TableRow firstRow = new TableRow();

            TableCell firstCell = new TableCell();

            TableCell locateButtonCell = new TableCell();

            locateButtonCell.Controls.Add(Locate);

            locateButtonCell.Width = 32;

            firstCell.Controls.Add(StrAddress);

            firstRow.Cells.Add(firstCell);

            firstRow.Cells.Add(locateButtonCell);

            TableRow seccondRow = new TableRow();

            TableCell seccondCell = new TableCell();

            seccondCell.Controls.Add(Localty);

            seccondRow.Cells.Add(seccondCell);

            TableRow thirdRow = new TableRow();

            TableCell thirdCell = new TableCell();

            TableCell acceptButtonCell = new TableCell();

            acceptButtonCell.Controls.Add(Accept);

            acceptButtonCell.Width = 32;

            thirdCell.Controls.Add(Country);

            thirdRow.Cells.Add(thirdCell);

            thirdRow.Cells.Add(acceptButtonCell);

 

            table.Rows.Add(firstRow);

            table.Rows.Add(seccondRow);

            table.Rows.Add(thirdRow);

 

            table.BorderWidth = 1;

            table.Width = 280;

 

            return table;

        }

 

        protected void Locate_Click(object sender, EventArgs e)

        {

            onLocateClick(e);

        }

 

        protected virtual void onLocateClick(EventArgs e)

        {

            if (locateClick != null)

            {

                locateClick(this, e);

            }

        }

And here's the control being used in the main page

protected void Button1_Click(object sender, EventArgs e)

        {

            foreach (GeoData geodata in GoogleGeocoder.GetGeoList(this.TextBox1.Text, true))

            {

                GeoLocationResulto gs = new GeoLocationResulto();

                gs.locateClick += new EventHandler(locateOnMap);

                this.Panel1.Controls.Add(gs.generateControls(geodata));

            }

            geoLocationControl.Update();

        }

 

        protected void locateOnMap(object sender, EventArgs e)

        {

            Button1.Text = "foo";

        }

when the button is clicked, the control shows up, but, upon clicking the button that should fire "locateOnMap", the whole page is reloaded instead of the expected behavior.

Make sure that the method generateControls must be execute on each time when a page is posted back.

where do you suggest to check the postback?
because the page will be always postback when i click on the imgButton, so the control will be rendered again

here is the aspx

<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="searchForm" runat="server">
        <ContentTemplate>
            <div>
                <asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox>
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="False" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <table width="100%">
        <tr>
            <td>
                <asp:UpdatePanel ID="geoLocationControl" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Panel ID="Panel1" runat="server" Width="300" ScrollBars="Auto" Height="500">
                        </asp:Panel>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
            <td>
                <asp:UpdatePanel ID="geoPanel" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <cc1:GMap ID="GMap1" runat="server" enableHookMouseWheelToZoom="True" enableServerEvents="true"
                            enableRotation="True" Height="500px" OnClick="GMap1_Click" OnMarkerClick="GMap1_MarkerClick"
                            Width="900px" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    </form>
</body>

i want to change the text of the button1 when i click on the control, but it only reloads the page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.