1

There is ImageButton and LinkButton combined in a span and bounded with same ClickEvent to exit from current location. enter image description here On the same page there searchTextBox and button to start search action.

Now the problem is:

  • When I enter some text in textbox and hit ENTER to perform search action (it searched the data) and then clicked on LinkButton to exit, the LinkButton event not getting fire but imageButton event is getting fired.
  • Did same action as above but instead of hitting ENTER to search I clicked on search button and then I click on LinkbUtton to exit. Now the event getting fired on click of both i.e. ImageButton and LinkButton.

Why only ImageButton event is working and not LinkButton event when I search the text by pressing ENTER key.

        LinkButton newUtilityLink;

        //Separator
        Panel_UtilityLink.Controls.Add(CreateUtilityLinkSeparator());

        HtmlGenericControl span = new HtmlGenericControl("span");
        span.ID = "ExitSpanId";
        span.AddCssClass("exitspan");

        ImageButton buttonExit = new ImageButton();
        buttonExit.ID = "IDButtonExit";
        buttonExit.ImageUrl = "~/WebResources/Exit.gif";
        buttonExit.Click += new ImageClickEventHandler(UtilityLink_Click);
        buttonExit.ImageAlign = ImageAlign.Bottom;
        span.Controls.Add(buttonExit);

        newUtilityLink = new LinkButton();
        newUtilityLink.ID = "IDULinkExit";
        newUtilityLink.Text = "Exit";
        newUtilityLink.Attributes.Add("EVENT", "eventExit");
        newUtilityLink.Click += new EventHandler(UtilityLink_Click); 
        span.Controls.Add(newUtilityLink);

        Panel_UtilityLink.Controls.Add(span);

Edit 1: HTML code <span class="exitspan" id="ExitSpanId"> <input name="ctl00$IDButtonExit" align="bottom" id="IDButtonExit" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" type="image" src="WebResources/Exit.gif"/> <a id="IDLinkExit" href="javascript:__doPostBack('ctl00$IDLinkExit','')" EVENT="eventExit">

Edit 2: Reason

I feel the actual cause is from Update Panel. On Hit Enter on search box does not performing Postback so Link is not getting bind. When I added AutopostBack trigger in update panel it started working but PAGE STARTED FLICKERING.

`<div id="SearchZone" runat="server">
    <span id="SearchTextSpan">
       <asp:Label ID="Label2" runat="server" meta:resourceKey="LabelSearch" />
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <asp:TextBox runat="server" Width="200px" ID="TextBoxSearch" MaxLength="70" />
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
       <asp:Button runat="server" ID="ButtonSearch" meta:resourceKey="ButtonSearch" cssClass="button" Width="150px" OnClick="ButtonSearch_Click"  />
       <asp:HiddenField ID="PreviousSearchIndex" runat="server" />
   </div>                    
   </asp:Panel>
   </ContentTemplate>
   <Triggers>
       <asp:PostBackTrigger ControlID="ButtonSearch" />
   </Triggers>
</asp:UpdatePanel>   `
PawanS
  • 7,033
  • 14
  • 43
  • 71
  • Why do you put together a LinkButton and an ImageButton since they do the same thing – DadyFuji May 21 '14 at 13:37
  • WHat happens with the page aright after you hit Enter? – Andrei May 21 '14 at 13:41
  • @nrsharma Not that does not help. There was not autopostback property for link button but I have used `newUtilityLink.Attributes.Add("onClick", "return true;");` – PawanS May 21 '14 at 14:11
  • @DadyFuji It is a same functionality as button with image and text. I know there are other way to achieve it but it is existing and rare cases to change it – PawanS May 21 '14 at 14:13
  • @Andrei It behaves the same way as it is doing after clicking the search button. – PawanS May 21 '14 at 14:14
  • Please enter some text in textbox and hit ENTER to perform search action, after that using your browser's inspector (F12) check and give us the value of the onclick attribute of your LinkButton. – DadyFuji May 21 '14 at 15:22
  • @DadyFuji I have edited in question. Please check – PawanS May 22 '14 at 07:49
  • when you click on your LinkButton, do you get errors on your browser 's JS consol ? – DadyFuji May 22 '14 at 13:57

1 Answers1

1

Looking at HTML code I can see the reason why LinkButton event is not fired.

Id of element is 'IDLinkExit' while value passed to __doPostback is 'ctl00$IDLinkExit'

Compare HTML code before and after you hit enter and see if id changes. You can also debug your code and see what's the value of ClientID for LinkButton.

PrzemG
  • 775
  • 6
  • 7