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];




                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.Width = 32;




            TableRow seccondRow = new TableRow();

            TableCell seccondCell = new TableCell();



            TableRow thirdRow = new TableRow();

            TableCell thirdCell = new TableCell();

            TableCell acceptButtonCell = new TableCell();


            acceptButtonCell.Width = 32;









            table.BorderWidth = 1;

            table.Width = 280;


            return table;



        protected void Locate_Click(object sender, EventArgs 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);






        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.

Recommended Answers

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

Jump to Post

All 2 Replies

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

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

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 learning and sharing knowledge.