c# - asp:Button not displaying correctly -


this scenario:

i want display button(btngenerate) based on amount of rows displayed in gridview. i've gotten display second goes away again. i'm using onclientclick of 1 of other buttons(btnimport). think causing problem on same button(btnimport)'s onclick event 2 gridview's performs each databind. problem? have written script using javascript perform task client side. there better way it? can fix problem?

here code have far:

<asp:button runat="server" id="btnimport" text="load data file"       backcolor="#990000" forecolor="white" nowrap onclick="btnimport_click"       style="display:none" onclientclick="displaybuttongenerate()"/>  <asp:button id="btngenerate" runat="server" text="generate new stock codes"      backcolor="#990000" forecolor="white" onclick="btngenerate_click"      style="display:none" /> 

i have 2 gridviews : errorsgrid displays faulty records , inventorygrid displays records correct. said above, idea display btngenerate if errorsgrid has rowcount=0.

protected void btnimport_click(object sender, eventargs e) {     inventorygrid.databind();     errorsgrid.databind();         }  protected void btngenerate_click(object sender, eventargs e) {     finalmessage.appendline(_insertwrapper.postdata()); } 

here script:

<script language="javascript" type="text/javascript">     function displaybuttongenerate() {         var rowcount = <%=errorsgrid.rows.count %>;         var buttongen = document.getelementbyid("<%=btngenerate.clientid%>");         if(rowcount == 0)         {             buttongen.style.display = "block";         }     }  </script> 

your btnimport has server-side onclient , client-side onclientclick both set. guess what's happening client-side called first, shows button, server-side 1 kicks in, page gets refreshed server, , button hidden again. can in 1 way or another, not both:

server-side: remove onclientclick & style="display:none" & javascript, set visible property of button false, , in code-behind click event on server add:

if(errorsgrid.rows.count == 0)     btnimport.visible = true; 

client-side: return false javascript function onclientclick:

onclientclick="return displaybuttongenerate()"  function displaybuttongenerate() {   ....   return false; }  

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -