how to read data of a dynamiclly loaded Web User Control

Posted by Sahoomanoj27 under ASP.NET on 1/11/2012 | Points: 10 | Views : 1191 | Status : [Member] | Replies : 5
How to get the value of a dynamically loaded web user control.

It's very urgent.




Responses

Posted by: Sksamantaray on: 1/11/2012 [Member] Silver | Points: 25

Up
0
Down
Control ctl = this.LoadControl("~/WebUserControl.ascx");
// Must set ctl ID
ctl.ID = "viewctl";
this.form1.Controls.Add(ctl);
Label mylbl=(Label)ctl.FindControl("Label1");
Response.Write(mylbl.Text);


I thinkk, this will solve your issue?
Click on Login to Mark as Answer, if it answers your query.
Thanks
Sanjay

Thanks,
Sanjay

Sahoomanoj27, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sahoomanoj27 on: 1/11/2012 [Member] Starter | Points: 25

Up
0
Down
I have loaded the webuser control dynamiclly during the page load event.
But i want to show the value of a control on button click event.
this is my question.

Sahoomanoj27, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/11/2012 [Member] Silver | Points: 25

Up
0
Down
 <form id="form1" runat="server">

<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>

---------------
codebehind


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
static int i = 0;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
i++;
Label1.Text = "Button is clicked" + i.ToString();
if(!Page.IsPostBack )

i++;
Label1.Text = "Button is clicked" + i.ToString();
}
}


Thanks,
Sanjay

Sahoomanoj27, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sahoomanoj27 on: 1/11/2012 [Member] Starter | Points: 25

Up
0
Down
U have written the codes behind th ascx page.
But i want to display the value of a control which is called in a aspx page by using findcontrol keyword

Thank u

Sahoomanoj27, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/11/2012 [Member] Silver | Points: 25

Up
0
Down
using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class webusercontroltest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
// showValue();
}

}
protected void Button1_Click(object sender, EventArgs e)
{
showValue();
}

protected void showValue()
{
Control ctl = this.LoadControl("~/WebUserControl.ascx");
// Must set ctl ID
ctl.ID = "viewctl";
this.form1.Controls.Add(ctl);
Label mylbl = (Label)ctl.FindControl("Label1");
Response.Write(mylbl.Text);
}
}


Thanks,
Sanjay

Sahoomanoj27, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response