Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 16th, 2016, 08: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
Reply With Quote
  #2 (permalink)  
Old December 18th, 2016, 09:29 AM
Imar's Avatar
Wrox Author
Points: 70,969, Level: 100
Points: 70,969, Level: 100 Points: 70,969, Level: 100 Points: 70,969, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,919
Thanks: 79
Thanked 1,550 Times in 1,527 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!
Reply With Quote
  #3 (permalink)  
Old December 18th, 2016, 10: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
Reply With Quote
  #4 (permalink)  
Old December 18th, 2016, 02:00 PM
Imar's Avatar
Wrox Author
Points: 70,969, Level: 100
Points: 70,969, Level: 100 Points: 70,969, Level: 100 Points: 70,969, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,919
Thanks: 79
Thanked 1,550 Times in 1,527 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!
Reply With Quote
  #5 (permalink)  
Old January 29th, 2017, 08: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.
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 08:32 PM
Mobile Control in System.Web.UI.Page hpfarstad ASP.NET 2.0 Professional 0 August 28th, 2006 05:00 AM



All times are GMT -4. The time now is 04:13 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.