0

i clicked abutton then depug enter page load before button click event i want to check in page load if this button clicked

i used hiddenfield and javascript function like

   <script type="text/javascript">
 function CheckClicked() {
     form1.HiddenField2.Value = span1.innerHTML;
      alert(form1.HiddenField2.Value);

   }
  </script>

and this is my button

<asp:Button id="cmd_Edit" CssClass="button rnd-sml" runat="server" text="edit" OnClick="cmd_Edit_Click" Visible="False" onclientclick="CheckClicked()" />

OK when click alert popup and it's value is true

when i checked in page_load event like

           if (HiddenField2.Value!="True")
            {
                FillData();
            }

HiddenField2.Value =null i don't know why where it's value(True) there was true in alert when came to page load became null

i need method to know if my button clicked before entered to button click event is there? plz i need help

user1637402
  • 87
  • 4
  • 15

2 Answers2

1

Page Load event is raised before postback values are processed.

Try to call "FillData" on OnPreRender event to prevent from this.

ertan
  • 645
  • 1
  • 7
  • 14
  • not working i need method to know if my button clicked before entered to button click event is there? – user1637402 Sep 20 '12 at 18:13
  • use an private variable to hold "clicked" state and perform final operations on OnPreRender – ertan Sep 20 '12 at 18:24
  • private bool editClick = false; private cmd_Edit_Click(object sender,..) { editClick = true; } private Page_OnPreRender(object sender, ..) { if (editClick) { FillData() } ); sorry for lack of space. – ertan Sep 20 '12 at 18:41
  • no no these mean that i will wait until enter to click event when i clicked enter pageload event before click in this place i want to know if button clicked or not – user1637402 Sep 20 '12 at 18:46
0

First, have you checked the actual name of your hidden field on the page? Asp .net likes to change them from what you think they are, so the name will probably be different for javascript. Also, try document.getElementById('whatever_the_id_is').value = document.getElementById('your_span').innerHTML; which uses IDs instead of names.

Steven Hunt
  • 2,321
  • 19
  • 18