Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdate Main page from user control
    text
    copied!<p>I have a grid view in my main page and I display some data for user(using <code>BindGrid</code> method).this grid view has some command buttons for each row that perform some operation like <code>Update</code>. when user clicks on update button I show to him/her a user control to update values.and when user clicks on update I want grid bind to new data(I want call <code>BindGrid</code> for new data). How I can do this and call a method in main page from user control?</p> <p><strong>Edit 1)</strong></p> <p>I wrote this code for user control:</p> <pre><code>public partial class SomeUserControl : System.Web.UI.UserControl { public event EventHandler StatusUpdated; private void FunctionThatRaisesEvent() { if (this.StatusUpdated != null) this.StatusUpdated(new object(), new EventArgs()); } public void Page_Load(object sender, EventArgs e) { //.... } protected void Button1_Click(object sender, EventArgs e) { FunctionThatRaisesEvent(); } } </code></pre> <p>and the designer for user control :</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="SomeUserControl.ascx.cs" Inherits="SomeUserControl" %&gt; &lt;asp:Button ID="Button1" runat="server" Text="Update" Height="70px" onclick="Button1_Click" Width="183px" /&gt; </code></pre> <p>and add this code for main page:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { } protected void Unnamed1_Click(object sender, EventArgs e) { SomeUserControl userControl = (SomeUserControl)LoadControl("SomeUserControl.ascx"); userControl.StatusUpdated += new EventHandler(userControl_StatusUpdated); Panel1.Controls.Add(userControl); } void userControl_StatusUpdated(object sender, EventArgs e) { GetDate(); } private void GetDate() { TextBox1.Text = DateTime.Today.ToString(); } </code></pre> <p>and designer for main page:</p> <pre><code>&lt;%@ Register src="SomeUserControl.ascx" tagname="SomeUserControl" tagprefix="uc1" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;/asp:ScriptManager&gt; &lt;div&gt; &lt;asp:UpdatePanel ID="upd1" runat="server" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button runat="server" Text="Add User Control" Height="44px" ID="Nims" onclick="Unnamed1_Click" Width="133px" /&gt; &lt;asp:Panel ID="Panel1" runat="server" BackColor="#FFFFCC"&gt;&lt;/asp:Panel&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>but it does not work and nothing happend. even I add break point for click user control button code but it seems that event not raise.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload