Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
| Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2016, 09:01 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Concatenate AppSetting key value into web page control attribute value

Hello,
I have a problem with one of my pages. I need to get the key value from my web.config file as a “prefix”, and concatenate the one with the string. Then assign the resulting string to “myTable” attribute of the control. I’ve tried different approaches, but no lack. I am missing something.
This is the ORIGINAL controls' code:
Code:
<cc1:BaseRadioButtonList ID="rblUserRegisterationType" runat="server" myAutoBind="True"
                                                myBoundField="Type" myTable="vUserRegisterationType" myFieldSet="TextField,ValueField"
                                                myOrder="TextField" DataTextField="TextField" DataValueField="ValueField" myShowSelectFromList="True"
                                                RepeatColumns="2" RepeatDirection="Horizontal" OnSelectedIndexChanged="rblUserRegisterationType_OnSelectedIndexChanged"
                                                AutoPostBack="true" myFilter="" Visible="false">
                                            </cc1:BaseRadioButtonList>
I was trying to get the key value from the web.config file like this, and concatenate the one with an existing myTable string "vUserRegisterationType":

Code:
 <%$AppSettings:LinkedServerHtmlPrefix%> 
, where in the web.config line is:

Code:
 <add key="LinkedServerHtmlPrefix" value="[FWC-VMSD1].[FWC_Users].[dbo]." />
I need to make my final attribute “myTable” looking like this:
myTable="[FWC-VMSD1].[FWC_Users].[dbo].vUserRegisterationType"

Question: how concatenate the string from the web.config and current “vUserRegisterationType”?

Any help will be appreciated.
--Dmitriy
 
Old December 18th, 2016, 10:29 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Do you own the BaseRadioButtonList class? If so, you could modify the control and add an additional property for the prefix part and concatenate them inside the control.

As an alternative, you could build a custom ExpressionBuilder:
http://www.4guysfromrolla.com/articles/022509-1.aspx

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 18th, 2016, 11:04 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
Thanks for the response. Unfortunately this BaseRadioButtonList control class created by 3rd party, and I do not have access to the code. This is why I am trying to concatenate the key value from the web.config file and an existing “myTable” attribute name, by using that Expression Builder you’ve mentioned someway. I’ve been trying different approaches, but it did not work:

Code:
myTable= <%$AppSettings:LinkedServerHtmlPrefix%> + "vUserRegisterationType” 
or
Code:
myTable= <%$ ConfigurationSettings.AppSettings["LinkedServerHtmlPrefix "] %> + "vUserRegisterationType”
or
Code:
myTable= <%= ConfigurationSettings.AppSettings["LinkedServerHtmlPrefix "] %> + "vUserRegisterationType”
or
Code:
myTable= <%# ConfigurationSettings.AppSettings["LinkedServerHtmlPrefix "] %> + "vUserRegisterationType”
I am out of ideas…

Thanks again,
Dmitriy
 
Old December 18th, 2016, 03:00 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You need to build your own ExpressionBuilder as explained in the section Creating a Custom Expression Builder Class in the article I linked to.

Alternatively, you could inherit the custom control you have, add your own property, inside that access AppSettings and set the property of the base class.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 29th, 2017, 09:33 PM
Friend of Wrox
Points: 528, Level: 8
Points: 528, Level: 8 Points: 528, Level: 8 Points: 528, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

A complex solution to a simple problem is a sign of bad design. why don't you just add the prefix in the declaration of the custom control. its not hard to change on the fly (with out recompiling) if you ever need to change it. after all an aspx page or ascx control is just a configuration file.




Similar Threads
Thread Thread Starter Forum Replies Last Post
A Web Part or Web Form Control on this Page cannot be displayed or imported. The typ Oak12 BOOK: Beginning SharePoint 2010 Development 1 July 2nd, 2010 02:00 PM
VB 2005 Appsetting smp4774 BOOK: Beginning VB.NET Databases 6 August 13th, 2008 04:57 AM
graph control on a web page? newjohno ASP.NET 2.0 Basics 1 June 15th, 2007 07:18 AM
Master Page Control/Web.Sitemap Questions kwilliams ASP.NET 2.0 Professional 2 January 14th, 2007 09:32 PM
Mobile Control in System.Web.UI.Page hpfarstad ASP.NET 2.0 Professional 0 August 28th, 2006 05:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.