ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.[Solved] Button Click not firing inside ASP.Net UpdatePanel with Master Page<p>Hi <a class="username" rel="fredo1094"> fredo1094</a>,</p> <p>You need remove is not postback code from master page.</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <p><strong>MasterPage.master</strong></p> <pre class="brush: html">&lt;%@ Master Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;MasterPage.master.cs&#34; Inherits=&#34;MasterPage&#34; %&gt; &lt;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&gt; &lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;link href=&#34;StyleSheet.css&#34; rel=&#34;stylesheet&#34; /&gt; &lt;style type=&#34;text/css&#34;&gt; @font-face { font-family: &#39;Material Icons&#39;; font-style: normal; font-weight: 400; src: url(https://fonts.gstatic.com/s/materialicons/v48/flUhRq6tzZclQEJ-Vdg-IuiaDsNa.woff) format(&#39;woff&#39;); } .material-icons { font-family: &#39;Material Icons&#39;; font-weight: normal; font-style: normal; font-size: 24px; line-height: 1; letter-spacing: normal; text-transform: none; display: inline-block; white-space: nowrap; word-wrap: normal; direction: ltr; -moz-font-feature-settings: &#39;liga&#39;; -moz-osx-font-smoothing: grayscale; } &lt;/style&gt; &lt;asp:ContentPlaceHolder ID=&#34;head&#34; runat=&#34;server&#34;&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; &lt;div&gt; &lt;header&gt; &lt;div&gt; &lt;nav class=&#34;navegacion clearfix&#34;&gt; &lt;div class=&#34;logo&#34;&gt; &lt;img src=&#34;img/LogoTP.png&#34; alt=&#34;&#34;&gt; &lt;/div&gt; &lt;div class=&#34;conten-iconos clearfix&#34;&gt; &lt;li class=&#34;icono&#34;&gt;&lt;a href=&#34;#Alerts&#34;&gt;&lt;i class=&#34;material-icons&#34;&gt;notifications&lt;/i&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class=&#34;icono&#34;&gt;&lt;a href=&#34;#Help&#34;&gt;&lt;i class=&#34;material-icons&#34;&gt;help&lt;/i&gt;&lt;/a&gt;&lt;/li&gt; &lt;li class=&#34;dropdown icono&#34;&gt; &lt;a href=&#34;#UserMenu&#34; class=&#34;dropdown-toggle&#34; data-toggle=&#34;dropdown&#34; role=&#34;button&#34; aria-haspopup=&#34;true&#34; aria-expanded=&#34;false&#34;&gt; &lt;i class=&#34;material-icons user-icon&#34;&gt;person&lt;/i&gt; &lt;/a&gt; &lt;ul class=&#34;dropdown-menu&#34;&gt; &lt;li&gt; &lt;strong&gt; &lt;asp:label ID=&#34;Saludo&#34; runat=&#34;server&#34; style=&#34;color:black&#34;&gt;&lt;/asp:label&gt; &lt;/strong&gt; &lt;/li&gt; &lt;li role=&#34;separator&#34; class=&#34;divider&#34;&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&#34;cambioclave/cambioclave.aspx&#34;&gt;Cambio Clave&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&#34;#Logout&#34;&gt;Logout&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/div&gt; &lt;/nav&gt; &lt;/div&gt; &lt;/header&gt; &lt;/div&gt; &lt;div class=&#34;contenedorFormularrio clearfix&#34;&gt; &lt;div class=&#34;contenedor-menu clearfix&#34;&gt; &lt;div class=&#34;clearfix menu&#34;&gt; &lt;nav&gt; &lt;asp:Panel class=&#34;acordeon&#34; ID=&#34;listMenu&#34; runat=&#34;server&#34;&gt;&lt;/asp:Panel&gt; &lt;/nav&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;conten-formulario&#34;&gt; &lt;div class=&#34;conten-opciones&#34;&gt; &lt;asp:ContentPlaceHolder ID=&#34;ContentPlaceHolder2&#34; runat=&#34;server&#34;&gt; &lt;/asp:ContentPlaceHolder&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </pre> <p><strong>Default.aspx</strong></p> <pre class="brush: html">&lt;%@ Page Title=&#34;&#34; Language=&#34;C#&#34; MasterPageFile=&#34;~/MasterPage.master&#34; AutoEventWireup=&#34;true&#34; CodeFile=&#34;Default.aspx.cs&#34; Inherits=&#34;_Default&#34; %&gt; &lt;asp:Content ID=&#34;Content1&#34; ContentPlaceHolderID=&#34;head&#34; runat=&#34;Server&#34;&gt; &lt;/asp:Content&gt; &lt;asp:Content ID=&#34;Content2&#34; ContentPlaceHolderID=&#34;ContentPlaceHolder2&#34; runat=&#34;Server&#34;&gt; &lt;asp:FileUpload ID=&#34;Upload&#34; runat=&#34;server&#34; Width=&#34;678px&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:ScriptManager ID=&#34;ScriptManager1&#34; runat=&#34;server&#34; /&gt; &lt;asp:UpdatePanel runat=&#34;server&#34; ID=&#34;UpdatePanel&#34; UpdateMode=&#34;Conditional&#34; ChildrenAsTriggers=&#34;true&#34;&gt; &lt;Triggers&gt; &lt;asp:PostBackTrigger ControlID=&#34;btnVisualizarArchivo&#34; /&gt; &lt;/Triggers&gt; &lt;ContentTemplate&gt; &lt;asp:Button ID=&#34;btnVisualizarArchivo&#34; class=&#34;btnButton&#34; runat=&#34;server&#34; Text=&#34;Visualizar&#34; OnClick=&#34;btnVisualizarArchivo_Click&#34; /&gt; &lt;asp:Button ID=&#34;btnCargarArchivo&#34; class=&#34;btnButton&#34; runat=&#34;server&#34; Text=&#34;Cargar&#34; OnClick=&#34;btnCargarArchivo_Click&#34; /&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;div class=&#34;scrolling-table-container&#34;&gt; &lt;asp:GridView ID=&#34;grdArchivo&#34; runat=&#34;server&#34; AutoGenerateColumns=&#34;true&#34;&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/asp:Content&gt; </pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <pre class="brush: csharp">using System.Data; using System.IO; </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>MasterPage.master.cs</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { fillMenu(); } public void fillMenu() { StringBuilder sb = new StringBuilder(); DataTable dtMenuParent = findParent(); DataTable dtMenuChild = findChild(); // try { if (dtMenuParent != null) { sb.AppendLine(&#34;&lt;ul&gt;&#34;); foreach (DataRow menuItem in dtMenuParent.Rows) { string menuId = menuItem[&#34;id&#34;].ToString(); string menuName = menuItem[&#34;MenuParent&#34;].ToString(); sb.Append(&#34;&lt;li class = &#39;clearfix&#39;&gt;&lt;a href=&#39;#&#34; + &#34;&#39;&gt;&#34; + menuName + &#34;&lt;/a&gt;&#34;); DataRow[] childMenu = dtMenuChild.Select(String.Format(&#34;id_parent=&#39;&#34; + menuItem[&#34;id&#34;] + &#34;&#39;&#34;)); foreach (DataRow subMenuItem in childMenu) { string subMenu = subMenuItem[&#34;MenuChild&#34;].ToString(); string url = subMenuItem[&#34;ChildMenu_URL&#34;].ToString(); sb.Append(&#34;&lt;ul&gt;&lt;li class=&#39;sub-menu&#39;&gt;&lt;a href=&#39;&#34; + url + &#34;&#39;&gt;&#34; + subMenu + &#34;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&#34;); } sb.Append(&#34;&lt;/li&gt;&#34;); } sb.Append(&#34;&lt;/ul&gt;&#34;); listMenu.Controls.Add(new LiteralControl(sb.ToString())); } } catch (Exception ex) { } } public DataTable findParent() { DataTable dtParent = new DataTable(); dtParent.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;id&#34;, typeof(int)), new DataColumn(&#34;MenuParent&#34;, typeof(string)) }); dtParent.Rows.Add(1, &#34;WorkForce&#34;); dtParent.Rows.Add(2, &#34;Conjuntos&#34;); dtParent.Rows.Add(3, &#34;Reporting&#34;); return dtParent; } public DataTable findChild() { DataTable dtChild = new DataTable(); dtChild.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;id&#34;, typeof(int)), new DataColumn(&#34;id_parent&#34;, typeof(int)), new DataColumn(&#34;MenuChild&#34;, typeof(string)), new DataColumn(&#34;ChildMenu_URL&#34;, typeof(string)) }); dtChild.Rows.Add(1, 1, &#34;HeadCount&#34;, &#34;Default.aspx&#34;); dtChild.Rows.Add(2, 2, &#34;Crear Conjunto&#34;, &#34;CConjuntos.aspx&#34;); dtChild.Rows.Add(2, 3, &#34;Crear&#34;, &#34;Default.aspx&#34;); return dtChild; }</pre> <p><strong>Default.aspx.cs</strong></p> <pre class="brush: csharp">public static DataTable dtDatos = new DataTable(); public DataTable visualizarArchivo() { dtDatos = new DataTable(); try { if (Upload.PostedFile.FileName == &#34;&#34;) { Response.Write(&#34;&lt;script&gt;alert(&#39;Seleccione un archivo&#39;);&lt;/script&gt;&#34;); } else { string ext = Path.GetExtension(Upload.PostedFile.FileName); switch (ext.ToLower()) { case &#34;.txt&#34;: using (StreamReader sr = new StreamReader(Upload.FileContent)) { string[] headers = sr.ReadLine().Split(&#39;\t&#39;); foreach (string header in headers) { dtDatos.Columns.Add(header); } while (!sr.EndOfStream) { string[] rows = sr.ReadLine().Split(&#39;\t&#39;); DataRow dr = dtDatos.NewRow(); for (int i = 0; i &lt; headers.Length; i++) { dr[i] = rows[i]; } dtDatos.Rows.Add(dr); } grdArchivo.DataSource = dtDatos; grdArchivo.DataBind(); } break; case &#34;.csv&#34;: using (StreamReader sr = new StreamReader(Upload.FileContent)) { string[] headers = sr.ReadLine().Split(&#39;;&#39;); foreach (string header in headers) { dtDatos.Columns.Add(header); } while (!sr.EndOfStream) { string[] rows = sr.ReadLine().Split(&#39;;&#39;); DataRow dr = dtDatos.NewRow(); for (int i = 0; i &lt; headers.Length; i++) { dr[i] = rows[i]; } dtDatos.Rows.Add(dr); } grdArchivo.DataSource = dtDatos; grdArchivo.DataBind(); } break; default: Response.Write(&#34;&lt;script&gt;alert(&#39;Archivo no permitido&#39;);&lt;/script&gt;&#34;); break; } } } catch (Exception ex) { throw ex; } return dtDatos; } private bool UploadFile() { bool bandera = false; try { if (Upload.HasFile) { string filename = Path.GetFileName(Upload.FileName); Upload.SaveAs(Server.MapPath(&#34;~/Archivos/&#34;) + filename); bandera = true; } else { bandera = false; } } catch (Exception ex) { throw ex; } return bandera; } protected void btnVisualizarArchivo_Click(object sender, EventArgs e) { if (UploadFile()) { btnCargarArchivo.Enabled = true; } visualizarArchivo(); } protected void btnCargarArchivo_Click(object sender, EventArgs e) { }</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/g9sgmIj.gif" alt="" width="303" height="503" /></p>https://www.aspforums.net:443/Threads/416803/Solved-Button-Click-not-firing-inside-ASPNet-UpdatePanel-with-Master-Page/https://www.aspforums.net:443/Threads/416803/Solved-Button-Click-not-firing-inside-ASPNet-UpdatePanel-with-Master-Page/Tue, 27 Aug 2019 04:50:33 GMT