Using Web User Control in a Web Part
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Using Web User Control in a Web Part

 
Post new topic   Reply to topic    Windows Server Forum Index -> Team Services
Author Message
Jerry
Guest





Posted: Fri Dec 03, 2004 7:53 pm    Post subject: Using Web User Control in a Web Part Reply with quote

Hi



I have a web user control that has a DataGrid Control and it is populated by
Custom Build Dataset filled by custom rows and column (Disconnected). It is
working properly when it is dragged in Simple ASP.net web page. But on the
other hand when i put these files in the IIS Default web site root folder
(e.g Mycontrols\gridcontrol.ascx) and use it in my web part and instal the
web part on the same site. The web part is not showing the DataGrid control
or any other thing infect I have tried with some other controls like text
box and button which are working properly but not with DataGrid control. I
am putting the code here for reference purpose. Please let me know where I
am not using the things right or please let me know if DataGrid control can
be used on a web user control which is placed on a web part.



Thanks



Web User Control Code (RecordControl.ascx.vb)

public DataTable myTable = new DataTable();

public DataRow objRow;

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
CreateRecord();
}

}

public void CreateRecord()
{

DataColumn myColumn= new DataColumn("First Name");
DataColumn myColumn1= new DataColumn("Middle Name");

myTable.Columns.Add(myColumn);
myTable.Columns.Add(myColumn1);

objRow=myTable.NewRow();
objRow[0]= "David";
objRow[1]= "Becham";
myTable.Rows.Add(objRow);



objRow=myTable.NewRow();
objRow[0]= "Christain";
objRow[1]= "Ronaldo";
myTable.Rows.Add(objRow);



DataGrid1.DataSource=myTable;
DataGrid1.DataBind();
}



Code for the Web Part

protected override void RenderWebPart(HtmlTextWriter output)
{
EnsureChildControls();

output.Write(SPEncode.HtmlEncode(Text));
output.Write("A Line Before Control Rendering");
_control.RenderControl(output);
}



protected override void CreateChildControls()
{
base.CreateChildControls ();
try
{



_control =this.Page.LoadControl("\\MyControls\\RecordControl.ascx");

//MyControl directory contains all three files of RecordControl, ascx,
ascx.vb,resx and the inherits tag from the top of Control is also
deleted.(web project name)
if ( _control !=null)
{
this.Controls.Add(_control);
}
}
catch (Exception ex)
{
Text=ex.ToString();
}



}



Thanks in advance



Jerry
Back to top
Mike Walsh
Guest





Posted: Fri Dec 03, 2004 8:57 pm    Post subject: Re: Using Web User Control in a Web Part Reply with quote

This is the newsgroup for SharePoint Team Services which doesn't have web
parts.

You either have Windows SharePoint Services (WSS) or SharePoint Portal
Server 2003 (SPS 2003).

The newsgroups are
WSS - microsoft.public.sharepoint.windowsservices
SPS 2003 - microsoft.public.sharepoint.portalserver

Please post to the newsgroup for the product you are running.

Mike Walsh, Helsinki, Finland
STS FAQ at http://www.collutions.com/Lists/FAQ
WSS FAQ at http://wss.collutions.com
Please post questions to the newsgroup only.


"Jerry" <jerry_yasir@microsoft.com> wrote in message
news:uJKJ$7T2EHA.1452@TK2MSFTNGP11.phx.gbl...
Quote:
Hi



I have a web user control that has a DataGrid Control and it is populated
by
Custom Build Dataset filled by custom rows and column (Disconnected). It
is
working properly when it is dragged in Simple ASP.net web page. But on
the
other hand when i put these files in the IIS Default web site root folder
(e.g Mycontrols\gridcontrol.ascx) and use it in my web part and instal the
web part on the same site. The web part is not showing the DataGrid
control
or any other thing infect I have tried with some other controls like text
box and button which are working properly but not with DataGrid control.
I
am putting the code here for reference purpose. Please let me know where
I
am not using the things right or please let me know if DataGrid control
can
be used on a web user control which is placed on a web part.



Thanks



Web User Control Code (RecordControl.ascx.vb)

public DataTable myTable = new DataTable();

public DataRow objRow;

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
CreateRecord();
}

}

public void CreateRecord()
{

DataColumn myColumn= new DataColumn("First Name");
DataColumn myColumn1= new DataColumn("Middle Name");

myTable.Columns.Add(myColumn);
myTable.Columns.Add(myColumn1);

objRow=myTable.NewRow();
objRow[0]= "David";
objRow[1]= "Becham";
myTable.Rows.Add(objRow);



objRow=myTable.NewRow();
objRow[0]= "Christain";
objRow[1]= "Ronaldo";
myTable.Rows.Add(objRow);



DataGrid1.DataSource=myTable;
DataGrid1.DataBind();
}



Code for the Web Part

protected override void RenderWebPart(HtmlTextWriter output)
{
EnsureChildControls();

output.Write(SPEncode.HtmlEncode(Text));
output.Write("A Line Before Control Rendering");
_control.RenderControl(output);
}



protected override void CreateChildControls()
{
base.CreateChildControls ();
try
{



_control =this.Page.LoadControl("\\MyControls\\RecordControl.ascx");

//MyControl directory contains all three files of RecordControl, ascx,
ascx.vb,resx and the inherits tag from the top of Control is also
deleted.(web project name)
if ( _control !=null)
{
this.Controls.Add(_control);
}
}
catch (Exception ex)
{
Text=ex.ToString();
}



}



Thanks in advance



Jerry

Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Team Services All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB