Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Control not getting value (http://www.velocityreviews.com/forums/t757435-control-not-getting-value.html)

Jon 02-08-2005 04:09 PM

Control not getting value
 
Hello all,

I've written the below server control which only half works! When I complie
and include the server control into a project I can get connectionString but
not storedProcedure, it always errors saying it's null, yet the code (seems)
is the same. Can anyone shed any light on this? Thanks:

[DefaultProperty("Text"),
ToolboxData("<{0}:TH_NKServerControl
runat=server></{0}:TH_NKServerControl>")]
public class TH_NKServerControl : System.Web.UI.WebControls.WebControl
{
private string storedProcedure;
private string connectionString;

DataGrid dgrdQuestions;
DataSet dsQuestions;

protected override void CreateChildControls()
{
Controls.Clear();
dgrdQuestions = new DataGrid();

dsQuestions = new DataSet();
dsQuestions = SqlHelper.ExecuteDataset(connectionString, storedProcedure);

dgrdQuestions.DataSource = dsQuestions;
dgrdQuestions.DataBind();

Controls.Add(dgrdQuestions);
}

[Bindable(true), Category("Data"), DefaultValue("")]
public string StoredProcedure
{
get
{
EnsureChildControls();
return storedProcedure;
}

set
{
storedProcedure = value;
EnsureChildControls();
}
}

[Bindable(true), Category("Data"), DefaultValue("")]
public string ConnectionString
{
get
{
EnsureChildControls();
return connectionString;
}

set
{
connectionString = value;
EnsureChildControls();
}
}
}
}

Jon 02-08-2005 04:15 PM

RE: Control not getting value
 
It seems that the code may not be the error but the usercontrol in the aspx
page. Whichever property comes second seems to cause the error, in tis case
connectionstring. Why's that?

<cc1:servercontrol id="TH_NKServerControl2" runat="server"
storedprocedure="sp_SelectAllFAQs" connectionstring="Persist Security
Info=False;Data Source=marge;Initial Catalog=Test;User
ID=webUser;Password=SQLS3rv3r"></cc1:servercontrol>

"Jon" wrote:

> Hello all,
>
> I've written the below server control which only half works! When I complie
> and include the server control into a project I can get connectionString but
> not storedProcedure, it always errors saying it's null, yet the code (seems)
> is the same. Can anyone shed any light on this? Thanks:
>
> [DefaultProperty("Text"),
> ToolboxData("<{0}:TH_NKServerControl
> runat=server></{0}:TH_NKServerControl>")]
> public class TH_NKServerControl : System.Web.UI.WebControls.WebControl
> {
> private string storedProcedure;
> private string connectionString;
>
> DataGrid dgrdQuestions;
> DataSet dsQuestions;
>
> protected override void CreateChildControls()
> {
> Controls.Clear();
> dgrdQuestions = new DataGrid();
>
> dsQuestions = new DataSet();
> dsQuestions = SqlHelper.ExecuteDataset(connectionString, storedProcedure);
>
> dgrdQuestions.DataSource = dsQuestions;
> dgrdQuestions.DataBind();
>
> Controls.Add(dgrdQuestions);
> }
>
> [Bindable(true), Category("Data"), DefaultValue("")]
> public string StoredProcedure
> {
> get
> {
> EnsureChildControls();
> return storedProcedure;
> }
>
> set
> {
> storedProcedure = value;
> EnsureChildControls();
> }
> }
>
> [Bindable(true), Category("Data"), DefaultValue("")]
> public string ConnectionString
> {
> get
> {
> EnsureChildControls();
> return connectionString;
> }
>
> set
> {
> connectionString = value;
> EnsureChildControls();
> }
> }
> }
> }


Chad 02-08-2005 04:30 PM

Re: Control not getting value
 
Try putting EnsureChildControls(); as the 1st line in all you're
property setter code.

IE:
set
{
EnsureChildControls();
connectionString = value;
}


Jon 02-08-2005 04:51 PM

Re: Control not getting value
 
Nope Chad, same error afraid.

Jon

"Chad" wrote:

> Try putting EnsureChildControls(); as the 1st line in all you're
> property setter code.
>
> IE:
> set
> {
> EnsureChildControls();
> connectionString = value;
> }
>
>


Chad 02-09-2005 02:32 PM

Re: Control not getting value
 
Also make sure you are Implementing INamingContainer I did this it
solved some problems for me. Also make sure EnsureChildControls is
everywhere in all subs/functions ... except for CreateChildControls
like you already had it.

You're code snippet did show where you were Overriding the base Render
code. Make sure to do that and make sure to put EnsureChildControls
before calling base.Render(output).

This is what I've done and I have 2 string property's and enum property
that all work great.

You got any thoughts on my problem. I'm also trying to add a property
of string array type. In the IDE I can fill in the property using the
property window. When I run it though I lose the property it behaves
just like what you are seeing the property is null. I'm also trying to
have a property that points to another control but I'm losing that at
run-time too. My guess is that a string array and a control are
non-native data types so there might be a trick to maintain the
settings between design time and run time.

Hope it works for you and hope you might a suggestion for me.... Chad


Jon wrote:
> Nope Chad, same error afraid.
>
> Jon
>
> "Chad" wrote:
>
> > Try putting EnsureChildControls(); as the 1st line in all you're
> > property setter code.
> >
> > IE:
> > set
> > {
> > EnsureChildControls();
> > connectionString = value;
> > }
> >
> >




All times are GMT. The time now is 08:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.