Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem accessing UserControl properties from ASP.NET Web Form CodeBehind

Reply
Thread Tools

Problem accessing UserControl properties from ASP.NET Web Form CodeBehind

 
 
jdn
Guest
Posts: n/a
 
      09-17-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Jacob Yang [MSFT]
Guest
Posts: n/a
 
      09-17-2003
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.

 
Reply With Quote
 
 
 
 
jdn
Guest
Posts: n/a
 
      09-17-2003
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
> (E-Mail Removed)
>


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

 
Reply With Quote
 
jdn
Guest
Posts: n/a
 
      09-17-2003
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
>> (E-Mail Removed)
>>

>
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing vb of usercontrol within usercontrol protic ASP .Net 0 10-15-2008 11:26 AM
accessing usercontrol from another usercontrol Phl ASP .Net 2 11-18-2004 07:33 PM
Accessing a usercontrol from parent codebehind Mat ASP .Net 4 10-29-2004 02:00 PM
Accessing usercontrol properties from another page - SERVER-SIDE John ASP .Net 2 10-17-2004 03:50 PM
Web Usercontrol in a Web Usercontrol not displaying... Kan Grewal ASP .Net Web Controls 2 07-07-2004 08:12 AM



Advertisments