Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Passing values to code behind - ASP.NET

Options
  • 29-08-2011 2:56pm
    #1
    Registered Users 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 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: 8,920 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 Posts: 3,992 ✭✭✭Korvanica


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


Advertisement