Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to access aspx.cs variable value in ascx page. I trying with hidden field but not working as expected. Some one give me an idea to do this.

Thanks.

What I have tried:

Aspx.cs
C#
string status = ucFormWizard.SaveDataToDB(commandData[1], Convert.ToInt32(commandData[2]), commandData[3], commandData[4], commandData[5]);
HiddenField hide = (HiddenField)ucFormWizard.FindControl("Hidden1");
hide.Value = status;


ascx page:
JavaScript
<asp:HiddenField ID="Hidden1" runat="server" />
function GetSlnForm() {
      var slnFormValue = document.getElementById('<%=Hidden1.ClientID%>').value;
}
Posted
Comments
F-ES Sitecore 25-Mar-19 7:29am    
If you view the source of the page does your hidden field contain a value?
Vincent Maverick Durano 26-Mar-19 11:54am    
What's not working? Are you getting error? Is the value from your HiddenField empty? Please be more specific so we can easily help you out.
Richard Deeming 26-Mar-19 15:14pm    
You should generally avoid using FindControl on a user control. Instead, add a public property to the .ascx.cs class, and set that property from the page class.

public class YourUserControl : UserControl
{
    public string Status
    {
        get { return Hidden1.Value; }
        set { Hidden1.Value = value; }
    }
    
    ...
}
string status = ucFormWizard.SaveDataToDB(commandData[1], Convert.ToInt32(commandData[2]), commandData[3], commandData[4], commandData[5]);
ucFormWizard.Status = status;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900