Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Passing values to code behind - ASP.NET

  • 29-08-2011 01:56PM
    #1
    Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭


    Ok so i have an ASCX user control on my page and need to pass values from this control to its code behind when a button is clicked.

    What's the best way at going about doing this ?

    I have some HiddenFields on the page already, do I need to perform a postback to be able to read them from code behind ?

    Currently they update fine (by the javascript) but when it goes to the codebehind all the values are blank.

    these are the required fields:
    <asp:HiddenField ID="NoteDateStrField" runat=server/>
    
          <asp:HiddenField ID="NoteIDField" Value="0" runat=server/>
    
          <asp:HiddenField ID="NoteContentsField" runat=server/>
    
    


    If a postback is necessary for the code behind to read these, how do I go about doing it? Do I postback to the ascx file itself? Or is it necessary to reload the whole aspx file ?


Comments

  • Registered Users, Registered Users 2 Posts: 1,311 ✭✭✭Procasinator


    If you don't want a full post back, you will have to use an Update Panel.

    Have a look at this article for the basic full postback handling in user control:
    http://msdn.microsoft.com/en-us/library/ms972975.aspx

    Update panels in user controls also has an article:
    http://msdn.microsoft.com/en-us/library/bb398780.aspx


  • Moderators, Science, Health & Environment Moderators Posts: 9,221 Mod ✭✭✭✭mewso


    It's not very clear to me where these controls are (the page aspx or the contorl ascx) although I assume they are on the aspx or you would easily access their values in the control's code behind. The overall picture of what you are trying to achieve here would probably make it easier to suggest solutions. Or alternatively use the proverbial lawnmower (update panel) to cut your hair (send values without postback) as suggested.


  • Registered Users, Registered Users 2 Posts: 3,992 ✭✭✭Korvanica


    Got it sorted with the update panel, cheers for the replies! :)


Advertisement