| | |
Update website control from usercontrol?
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
I was told to write the question here instead of in c# forum, so I post it here as well.
Hi..
I am trying to update a webcontrol on a main site from a usercontrol but how can this be done.
Let's say I want to update an asp:textbox from a usercontrol on the page, but how is this done most respectfully. The usercontrol does ofcause not know the controls from the main site but I guess that the "findcontrol"-method (in the usercontrol) executed on the parent-control must do what I need (as long that I check that the control exist on the main page); but how is this done.
Something like this maybe:
Hi..
I am trying to update a webcontrol on a main site from a usercontrol but how can this be done.
Let's say I want to update an asp:textbox from a usercontrol on the page, but how is this done most respectfully. The usercontrol does ofcause not know the controls from the main site but I guess that the "findcontrol"-method (in the usercontrol) executed on the parent-control must do what I need (as long that I check that the control exist on the main page); but how is this done.
Something like this maybe:
MAIN SITE:
<SOME TEXTBOX id="main">
<uc:USERCONTROL id="UC">
USERCONTROL codebehind somewhere:
((Textbox)This.parent???.findcontrol("main")).Text = "something from uc";•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
here is the example solution :
Default.aspx:
Default.aspx.cs :
WebUserControl.ascx:
WebUserControl.ascx.cs :
Default.aspx:
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <uc1:WebUserControl ID="WebUserControl1" runat="server" /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div> </form> </body> </html>
ASP.NET Syntax (Toggle Plain Text)
using System; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
WebUserControl.ascx:
ASP.NET Syntax (Toggle Plain Text)
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class WebUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { ((TextBox)Parent.FindControl("TextBox1")).Text = "something"; } }
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Jan 2008
Posts: 2,052
Reputation:
Solved Threads: 118
•
•
•
•
Thanks..
So my surgestion about "((TextBox)Parent.FindControl("TextBox1")).Text = "something";", as you also make use of, is the solution to do this? But the parent is rendered before the uc so this includes use of ajax I assume..?!
no this example does not use ajax.
Due to lack of freedom of speech, i no longer post on this website.
•
•
Join Date: Nov 2007
Posts: 28
Reputation:
Solved Threads: 0
•
•
•
•
i never send a post without trying it locally on my PC. As long as it works, why do you care which one is rendered first? if you really wonder it, just put a break point to load event handlers of both usercontrol and webform.
no this example does not use ajax.
My question on which is rendered first wasn't a real question but more a comment on the main page is rendered first which mean that the control referered to is not changed without changing the main site which is already rendered and lead to another postback. Understand my point.
The exact question is that i need ajax to render the main page when the usercontrol is making a postback, but how is this done without flickering/postback all the page.
To update the textfield (main site) for example I need to surround this by an updatepanel and then the textbox-control can be updated without flicker, but how do I ensure that the usercontrol's runat server command to update the updatepanel is not updating the usercontrol as well and make postback on this as well? should I surround all the usercontrol-controls with an updatepanel?
I don't know if I am clear in my question. If not let me know.
CODE MAIN SITE:
ASP.NET Syntax (Toggle Plain Text)
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Literal ID="LiteralMessages" runat="server"></asp:Literal> <br /> <uc1:WebUserControl ID="WebUserControl1" runat="server" /> </ContentTemplate> </asp:UpdatePanel>
CODE UC:
ASP.NET Syntax (Toggle Plain Text)
protected void cb_enabled_CheckedChanged(object sender, EventArgs e) { ... ((Literal)Parent.FindControl("LiteralMessages")).Text += Msg.PrintMessages(MYDLL.GetMessages(Request, Session)); ... } <asp:Label ID="lblName" runat="server" Width="150px"></asp:Label> <asp:CheckBox ID="cb_enabled" runat="server" oncheckedchanged="cb_enabled_CheckedChanged" AutoPostBack="true" />
What I want is that the checkbox when changed sends a message back to the main site and not postback the entire site so it flickers.
![]() |
Similar Threads
- How To Print Directly to Printer (PHP)
- Update website control from usercontrol? (C#)
- update NEWS portion on website via EMAIL? (Perl)
- Can't connect to any website hosted on a specific IP (Windows NT / 2000 / XP)
- ASP.net AJAX Update panel control (ASP.NET)
- Classifieds Ads Submission Website for Sell (Websites for Sale)
- Major new update of Website (Website Reviews)
- Big Time Bug On New Windows Update (Windows NT / 2000 / XP)
Other Threads in the ASP.NET Forum
- Previous Thread: SMS gateway Ozeki?
- Next Thread: server.mappath()
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash form formatdecimal formview gridview gudi iis javascript listbox login microsoft mono mouse mssql news novell numerical opera panelmasterpagebuttoncontrols parent problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers






