Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Problem accessing UserControl properties from ASP.NET Web Form CodeBehind (http://www.velocityreviews.com/forums/t771083-problem-accessing-usercontrol-properties-from-asp-net-web-form-codebehind.html)

jdn 09-17-2003 12:31 AM

Problem accessing UserControl properties from ASP.NET Web Form CodeBehind
 
I have a simple problem that probably requires a simple solution but I
am obviously overlooking something.

I have a Address form on a ASP.NET page that include a state field. I
created a simple user control that is a drop down list of all 50 states
plus DC.

On a certain function (basically calling OnItemCommand from a datagrid),
I bind various textboxes and labels to the values pulled from a stored
procedure and they all work fine. But the User Control never gets the
proper value.

The user control has a public property that should set the selected
value for that dropdownlist such as:

public static string SelectedValue {
get { return ddlStateList.SelectedValue; }
set { ddlStateList.SelectedValue = value; }
}

and then I try to bind the value as such in the page it is embedded in:

_DDLStateControl.SelectedValue = myDataRow["State"].ToString();

In debugging mode, the myDataRow value is correct, but it doesn't
acutally set the selected value at all.

I reference the User Control in the page itself with
TagPrefix="UserControl" and TagName="StateList"

I'm wondering if I should be doing something like
UserControl:Statelist.SelectedValue = blah

but I don't know what the correct syntax is.

TIA
jdn
kingcrim@earthlink.net


Jacob Yang [MSFT] 09-17-2003 03:02 PM

RE: Problem accessing UserControl properties from ASP.NET Web Form Code Behind
 
Hi Jdn,

I have reviewed your issue. Due to the nature of your issue I need to do
additional research to determine the best way to provide assistance. I will
contact you as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
<MCSD>
Get Secure! ĘC www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


jdn 09-17-2003 10:45 PM

Re: Problem accessing UserControl properties from ASP.NET Web FormCode Behind
 
jdn wrote:

> I have a simple problem that probably requires a simple solution but I
> am obviously overlooking something.
>
> I have a Address form on a ASP.NET page that include a state field. I
> created a simple user control that is a drop down list of all 50 states
> plus DC.
>
> On a certain function (basically calling OnItemCommand from a datagrid),
> I bind various textboxes and labels to the values pulled from a stored
> procedure and they all work fine. But the User Control never gets the
> proper value.
>
> The user control has a public property that should set the selected
> value for that dropdownlist such as:
>
> public static string SelectedValue {
> get { return ddlStateList.SelectedValue; }
> set { ddlStateList.SelectedValue = value; }
> }
>
> and then I try to bind the value as such in the page it is embedded in:
>
> _DDLStateControl.SelectedValue = myDataRow["State"].ToString();
>
> In debugging mode, the myDataRow value is correct, but it doesn't
> acutally set the selected value at all.
>
> I reference the User Control in the page itself with
> TagPrefix="UserControl" and TagName="StateList"
>
> I'm wondering if I should be doing something like
> UserControl:Statelist.SelectedValue = blah
>
> but I don't know what the correct syntax is.
>
> TIA
> jdn
> kingcrim@earthlink.net
>


Okay, I was able to fix the easy syntax part.

In the Page itself, the user control is given an id = "ucStateListControl"

So, in the code behind for the page, I can declare it like any other web
control:

protected _DDLStateListControl ucStateListControl;

and that works.

The problem now is I am getting a "specified argument was out of the
range of valid values" when I try to set the SelectedValue to "IL", even
though I have this ListItem in the DropDownList:

<asp:ListItem Value="IL" >IL</asp:ListItem>

I'm not sure why that is.

jdn


jdn 09-17-2003 11:39 PM

Re: Problem accessing UserControl properties from ASP.NET Web FormCode Behind
 
jdn wrote:

> jdn wrote:
>
>> I have a simple problem that probably requires a simple solution but I
>> am obviously overlooking something.
>>
>> I have a Address form on a ASP.NET page that include a state field. I
>> created a simple user control that is a drop down list of all 50
>> states plus DC.
>>
>> On a certain function (basically calling OnItemCommand from a
>> datagrid), I bind various textboxes and labels to the values pulled
>> from a stored procedure and they all work fine. But the User Control
>> never gets the proper value.
>>
>> The user control has a public property that should set the selected
>> value for that dropdownlist such as:
>>
>> public static string SelectedValue {
>> get { return ddlStateList.SelectedValue; }
>> set { ddlStateList.SelectedValue = value; }
>> }
>>
>> and then I try to bind the value as such in the page it is embedded in:
>>
>> _DDLStateControl.SelectedValue = myDataRow["State"].ToString();
>>
>> In debugging mode, the myDataRow value is correct, but it doesn't
>> acutally set the selected value at all.
>>
>> I reference the User Control in the page itself with
>> TagPrefix="UserControl" and TagName="StateList"
>>
>> I'm wondering if I should be doing something like
>> UserControl:Statelist.SelectedValue = blah
>>
>> but I don't know what the correct syntax is.
>>
>> TIA
>> jdn
>> kingcrim@earthlink.net
>>

>
> Okay, I was able to fix the easy syntax part.
>
> In the Page itself, the user control is given an id = "ucStateListControl"
>
> So, in the code behind for the page, I can declare it like any other web
> control:
>
> protected _DDLStateListControl ucStateListControl;
>
> and that works.
>
> The problem now is I am getting a "specified argument was out of the
> range of valid values" when I try to set the SelectedValue to "IL", even
> though I have this ListItem in the DropDownList:
>
> <asp:ListItem Value="IL" >IL</asp:ListItem>
>
> I'm not sure why that is.
>
> jdn
>


Fixed it.

Instead of trying to set the SelectedValue, I changed it to set the
SelectedItem.Text to what I was getting data from, and it worked just fine.

jdn



All times are GMT. The time now is 11:30 PM.

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