Re: loop througth Literials using foreach!!

From: Scott Allen (scott_at_nospam.odetocode.com)
Date: 02/11/05


Date: Thu, 10 Feb 2005 20:37:02 -0500

If there is a literal control on the page, the control has to be
instantiated to render. Perhaps you meant you didn't want to declare a
variable for each Literal control?

In any case, I think a cleaner solution would be to create a new
control (pehaps derived from Literal or WebControl) and use the Init
event to get the string from a resource file. You could add Key as a
public property to be able to assign the key from inside the ASPX tag.

The above approach will be a cleaner, more maintainable solution.
You'll be able to use the new control on any page in your application
without cluttering eeach page with the string loading logic.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 11 Feb 2005 03:13:07 +0200, "Islam Elkhayat"
<islamegy@yahoo.com> wrote:
>I want to loop throught literials so i don't use
>Lit_1.Text= resources.GetString(key)
>for each literial... if i instantiated every literial in the code behind i 
>will write the same long code!!!
>How can i solve this issue??
>
>
>"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message 
>news:O39xgU9DFHA.732@TK2MSFTNGP12.phx.gbl...
>> How are you creating your literals?  In my tests of your problem, I found 
>> that Literals created in the aspx file as <asp:LITERAL> were not available 
>> in code even if I made sure that they were declared and instantiated in my 
>> codebehind.
>>
>> In order to get the Literals to work, I had to create them, instantiate 
>> them, and them to Page.Controls from within my codebehind.  Done that way, 
>> I was able to access the Literal and manipulate its properties.
>>
>>
>> "Islam Elkhayat" <islamegy@yahoo.com> wrote in message 
>> news:OAaOtI9DFHA.3244@TK2MSFTNGP15.phx.gbl...
>>> It didn't throw Exception but also didn't work
>>> if statment always false... so i always go to the else!!
>>>
>>> How can i make it work??
>>>
>>
>> 
>


Relevant Pages

  • Re: Null pointer exception for events in usercontrols (C#)
    ... > I'm writing user controls with custom events. ... > custom control and add some text boxes, labels, buttons etc... ... > public delegate void PirEventHandler ... The fact is that I never instantiate this object as I ...
    (microsoft.public.dotnet.languages.csharp)
  • CCW/,NET UserControl lifetime question
    ... A CCW is created for IE to instantiate and call methods on this user ... control and every re-rendering of that page (due to user clicking the ... This should further release the sole reference to the .NET usercontrol ...
    (microsoft.public.dotnet.framework.interop)
  • Re: ActiveX Control will not instantiate
    ... ISetSite ... why IE will not instantiate an ActiveX control? ... I have written a custom ActiveX control in Visual Basic 6. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: loop througth Literials using foreach!!
    ... How do you currently load the resource manager? ... >I tried to create new control drived from Literial... ... >>>I want to loop throught literials so i don't use ... In order to get the Literals to work, I had to create them, instantiate ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: frmViewAll.DefInstance.Hide()
    ... If you want to show another form, Just declare it new. ... Public sub new ... a third party control, ...
    (microsoft.public.dotnet.languages.vb)