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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Passing values to code behind - ASP.NET

  • 29-08-2011 1: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,035 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