c# - Avoid page refresh when clicking on LinkButton in grid -


i have gridview control, , inside of control have defined link button using gridview.itemtemplate.

i using open new window on click. when click on link button, however, page refreshes before opening new window.

how can stop page refreshing after link button clicked?

pop not displaying when add update panel first grid

if remove update panel first grid, grid refreshing , popup displaying

i need open popup without refreshing grid

please find me solution working on past 2 days

html

<%@ page language="c#" autoeventwireup="false" codefile="viewdata1.aspx.cs" inherits="ablesas.viewdataui1" enableeventvalidation="false"%>               <asp:updatepanel id="updatepanel4" runat="server">                         <contenttemplate>                                           <asp:gridview id="datagrid1"  style="visibility:visible" runat="server" alternatingrowstyle-backcolor="#e9edf5"  font-names="arial"                                                 forecolor="#09538a" font-size="12px" backcolor="#ffffff" bordercolor="darkgray" font-bold="true"                                                  headerstyle-backcolor="#298dc7" enableviewstate="false"  cellspacing="20"                                                  cellpadding="10"  headerstyle-font-bold="true"  autogeneratecolumns="false" onrowcommand="datagrid1__rowcommand" onrowdatabound="datagrid1__rowdatabound" >                                                 <headerstyle font-names="arial;" cssclass="myheaderstyle" font-size="13px" forecolor="white" font-bold="true" height="20"  backcolor="#298dc7" ></headerstyle>         <asp:templatefield headertext="ndc" itemstyle-cssclass="col" itemstyle-horizontalalign="justify" headerstyle-width="10%" itemstyle-width="10%">                                     <columns>                                    <itemtemplate>                     <asp:linkbutton id="productcode"   forecolor="#09538a" runat="server"  text='<%#eval("product code")%>'></asp:linkbutton>                                                                                      </itemtemplate>                                         </asp:templatefield>                    </asp:gridview>                                 </contenttemplate>                 </asp:updatepanel>                                           <ajaxtoolkit:modalpopupextender id="modalpopupextender1"   backgroundcssclass="modalbackground" cancelcontrolid="cancel" targetcontrolid="button3" runat="server" popupcontrolid="pnlpopup"> </ajaxtoolkit:modalpopupextender>     <asp:panel id="panel1"  runat="server" height="30px" width="600px">     </asp:panel>                            <asp:button id="button3" runat="server" style="visibility:hidden" text="button" />                             <asp:panel id="pnlpopup" cssclass="panelpopup"  runat="server">                                         <div  style="width:inherit;text-align:center;">products of <%=ndc %> product family</div>                                         <asp:gridview id="gridview1"  runat="server" alternatingrowstyle-backcolor="#f1f4f8"  width="980px" font-names="arial"                                             font-bold="true" forecolor="#09538a" font-size="13px" backcolor="#ffffff" bordercolor="darkgray"                                             headerstyle-backcolor="#99cccc" enableviewstate="false"  cellspacing="0" style="padding:10px;"                                             cellpadding="3" showfooter="false" allowpaging="true" autogeneratecolumns="false" onrowdatabound="productinfo_rowdatabound" >                                             <headerstyle height="10%" cssclass="myheaderstyle" font-size="13px" forecolor="#ffffff" font-bold="true"  backcolor="#298dc7"></headerstyle>                                             <rowstyle height="20px" />                         <alternatingrowstyle  height="20px"/>                                             <columns>                 <asp:boundfield  datafield="product code" sortexpression="customers " itemstyle-cssclass="col" headertext="ndc"/>               <div id="div<%#  convert.tostring(eval("customer"))+ convert.tostring(eval("manufacturingpartner"))+ convert.tostring(eval("product code"))+ convert.tostring(eval("sales person")) %>" style="display: none; position: relative; left: 15px; overflow: auto">                                         <asp:gridview id="gvorderinfo" runat="server" forecolor="#09538a"  autogeneratecolumns="false" borderstyle="double"  bordercolor="#df5015"  width="500px" onrowdatabound="gvorderinfo_rowdatabound">                                         <headerstyle cssclass="myheaderstyle"  font-size="13px" forecolor="#ffffff" font-bold="true"  backcolor="#298dc7"></headerstyle>                                         <rowstyle backcolor="#e1e1e1" />                                         <alternatingrowstyle backcolor="white" />                                         <headerstyle backcolor="#df5015" font-bold="true" forecolor="white" />                                         <columns>               <asp:boundfield datafield="order number" headertext="order number" itemstyle-width="75px" itemstyle-cssclass="col" headerstyle-horizontalalign="left" />                   </columns>                  </columns>                                                                     </asp:gridview>                                     </div>                                                                      </asp:gridview>              </asp:panel> 

codebehind

  protected void datagrid1__rowdatabound(object sender, gridviewroweventargs e)     {              this.updatepanel4.update();          if (e.row.rowtype == datacontrolrowtype.datarow)          {               linkbutton lnk = e.row.findcontrol("productcode") linkbutton;               lnk.click += new eventhandler(link_click);                //scriptmanager.getcurrent(this).registerpostbackcontrol(lnk);                 // string = string.format("0:n}",convert.todecimal(e.row.cells[3].text));               if (e.row.cells[0].text != "total")               {                     //m1-fmodification starts here                     if (listbox2.items.count > 0)                     //if (datagrid1.columns[0].visible == true)                     {                     }                             }          }     } 

codebehind

 public void productcode_click(object sender, eventargs e)         {             pnlpopup.visible = true;             //updatepanel3.update();             //this.updatepanel3.update();             gridviewrow clickedrow = ((linkbutton)sender).namingcontainer gridviewrow;             linkbutton lbtn = (linkbutton)clickedrow.findcontrol("productcode");             string customer = clickedrow.cells[0].text.tostring();             string manufacturer = clickedrow.cells[5].text.tostring();             string salesperson = clickedrow.cells[6].text.tostring();             system.data.datatable newproducttable = null;             arraylist productdrilldownlist = new arraylist();             productdrilldownlist.add(customer);             productdrilldownlist.add(manufacturer);             productdrilldownlist.add(lbtn.text);             productdrilldownlist.add(salesperson);               try             {                 viewdata1 vdata = new viewdata1();                 dataset ds1 = vdata.__getprodoverviewdataset(__getconnectionstring());                 dataset ds2 = vdata.__getcustoverviewdataset(__getconnectionstring());                 dataset ds3 = vdata.__getsalesoverviewdataset(__getconnectionstring());                 dataset ds4 = vdata.__getmanoverviewdataset(__getconnectionstring());                 dataset ds5 = vdata.__getbookeddatedataset(__getconnectionstring());                  list<datetime> booked_date = new list<datetime>();                  if (ds5.tables[0].rows.count > 0)                 {                     foreach (datarow row in ds5.tables[0].rows)                     {                         if (row[0].tostring() != " " && row[0] != null)                         {                             booked_date.add(convert.todatetime(row[0]));                         }                     }                 }                 booked_date.remove(convert.todatetime("1/1/0001 12:00:00 am"));                 booked_date.sort();                 arraylist daterange = new arraylist();                 daterange = _getdaterange();                 if (convert.todatetime(daterange[0]) > convert.todatetime(daterange[1]))                 {                  //   datagrid1.visible = false;                  //   label4.visible = false;                 //    txtcustprod.visible = false;                 //    panel1.visible = false;                 //    clientscript.registerclientscriptblock(gettype(), "javascript", "<script>alert('there no data found')</script>");                 //    return;                 }                 if (todatetxtbox.text != "" && todatetxtbox.text != "to date" && fromdatetxtbox.text != "from date")                 {                     dropdownlist2.text = "months";                     dropdownlist3.text = "years";                     if (!booked_date.contains(convert.todatetime(daterange[2])) && !booked_date.contains(convert.todatetime(daterange[3])))                     {                      //   datagrid1.visible = false;                      //   label4.visible = false;                     //    txtcustprod.visible = false;                     //    panel1.visible = false;                     //    clientscript.registerclientscriptblock(gettype(), "javascript", "<script>alert('there no data found')</script>");                     }                 }                 else                 {                     todatetxtbox.text = "";                     fromdatetxtbox.text = "";                 }                     int countcustomer = -1;                 int countproduct = -1;                 int countsales = -1;                 int countman = -1;                 if (ds1.tables[0].rows.count > 0)                 {                     countproduct = ds1.tables[0].rows.count;                 }                 if (ds2.tables[0].rows.count > 0)                 {                     countcustomer = ds2.tables[0].rows.count;                 }                 if (ds3.tables[0].rows.count > 0)                 {                     countsales = ds3.tables[0].rows.count;                 }                 if (ds4.tables[0].rows.count > 0)                 {                     countman = ds4.tables[0].rows.count;                 }                   system.data.datatable dt = new system.data.datatable();                 string test = "";                 if(session["callcount"] != null){                     string coo = session["callcount"].tostring();                      int coi = int16.parse(coo);                     session["callcount"] = coi + 1;                     test = session["callcount"].tostring();                 }                 else{                     int coi = 0;                     session["callcount"] = coi.tostring();                     test = session["callcount"].tostring();                 }                 dt = vdata.__getproductlevelsource(__getconnectionstring(), __getdropdownvalues(), __getprodfiltervalues(), __getcustfiltervalues(), __getsalesfiltervalues(), __getmanfiltervalues(), countcustomer, countproduct, countsales, countman, _getdaterange(), __getprodfamilyfiltervalues(), productdrilldownlist);                 gridview1.datasource = dt;                 gridview1.databind();                 //dt.rows.count                 gridview_columnshide(gridview1);             }             catch (exception dateerr)             {                 //datagrid1.visible = false;                 //label4.visible = false;                 //txtcustprod.visible = false;                 //panel1.visible = false;                 //clientscript.registerclientscriptblock(gettype(), "javascript", "<script>alert('there no data found')</script>");              }              modalpopupextender1.show();             //updatepanel3.update();          } 

please try add model pop extender inside update panel.then pop out page refreshing.this sample code. 1 working without problem. check 1 more time

  <asp:updatepanel runat="server">     <contenttemplate>            <asp:gridview id="datagrid1" runat="server" onrowdatabound="datagrid1__rowdatabound">              <columns>                 <asp:boundfield datafield="id" headertext="value" />                 <asp:templatefield headertext="ndc" itemstyle-cssclass="col" itemstyle-horizontalalign="justify" headerstyle-width="10%" itemstyle-width="10%">                      <itemtemplate>                         <asp:linkbutton id="productcode" forecolor="#09538a" runat="server" text='click'></asp:linkbutton>                      </itemtemplate>                 </asp:templatefield>             </columns>         </asp:gridview>            <ajaxtoolkit:modalpopupextender id="modalpopupextender1" targetcontrolid="button3" runat="server" popupcontrolid="pnlpopup"></ajaxtoolkit:modalpopupextender>          <asp:button id="button3" runat="server" style="visibility: hidden" text="button" />         <asp:panel id="pnlpopup" cssclass="model-bd" runat="server">             <input type="button" value="ok">         </asp:panel>     </contenttemplate> </asp:updatepanel> 

----------c#------------

   protected void page_load(object sender, eventargs e)     {          datatable dt = new datatable();         dt.columns.add("id");         datarow dr = dt.newrow();         datarow dr1 = dt.newrow();         dr["id"] = 1;         dr1["id"] =21;         datagrid1.datasource = dt;         dt.rows.add(dr);         dt.rows.add(dr1);         datagrid1.databind();     }     protected void datagrid1__rowdatabound(object sender, gridviewroweventargs e)     {          if (e.row.rowtype == datacontrolrowtype.datarow)         {             linkbutton lnk = e.row.findcontrol("productcode") linkbutton;             lnk.click += new eventhandler(productcode_click);           }     }      void productcode_click(object sender, eventargs e)     {         pnlpopup.visible = true;            modalpopupextender1.show();       } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -