Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 May 22nd, 2007, 02:12 PM
Registered User
 
Join Date: Dec 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Server side on code on control property

Hi,
  I developed a customcontrol and I have a property call str_extra_parameters. I am trying to assign the value on the control definition itself. It is not working. It works when I assign it on code-behing on onInit event. How do I mingle server side and .aspx code together

The following doesn't work for me
<cc1:AutoSuggestCombobox
                    ID=AutoSuggest_User
                    runat=server
                    str_extra_parameter = <%# System.Web.HttpContext.Current.User.Identity.Name %>
                    ></cc1:AutoSuggestCombobox>

I tried putting string apostrophe before and after, no luck.

But the following works when I assign it on code-behind

protected override void OnInit(EventArgs e)
    {
        AutoSuggest_User.str_extra_parameters_for_stored_p rocedure = System.Web.HttpContext.Current.User.Identity.Name ;
        base.OnInit(e);
    }

Please help me to avoid code behind and put the code on aspx side itself

Thanks in advance

 
Old May 23rd, 2007, 08:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Using data binding syntax can be tricky. Normally you use that syntax in a control that will be explicitly bound by calling the .DataBind() method. However, you are trying to use this at the page level. Unless you bind the page, that databinding code will never be processed. What's wrong with letting the code behind do it?

One bit of advice for something like this... create a public method on the control to act as a "setter" for this value you need to pass it. Have that method fire off the code that needs the value. (I'm assuming that you are running the code that needs that value in the control's page_load event, which is why you have to put the value assignment in the OnInit handler of the page.) This provides more flexibility to the control and reduces (if not eliminates) the load order dependency on the control's behavior.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Converting Client-side to Server-side Code kwilliams ASP.NET 2.0 Professional 1 November 21st, 2007 05:25 PM
text-property in a non-server control propellis .NET Web Services 0 July 4th, 2006 03:29 AM
handling server side button visibility property shilpa528 General .NET 3 December 13th, 2004 05:32 AM
handling server side buttons visibility property d shilpa528 Java GUI 0 December 13th, 2004 03:02 AM
Pop-Up window from server side control jbenson001 ASP.NET 1.x and 2.0 Application Design 5 November 11th, 2003 05:00 PM





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