Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Assemblies
.NET Core
.NET Standard
Active Directory
ADO.NET
Agile Development
AJAX
Alexa Skills
Algorithms in C#
Android
Angular
Architecture
ArcObject
Artificial Intelligence
ASP.NET
ASP.NET Core
Augmented Reality
Aurelia
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blockchain
Bootstrap
Bot Framework
Business
C#
C# Corner
C, C++, MFC
Career Advice
Chapters
CIO
Cloud
COBOL.NET
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Cortana Development
Cryptocurrency
Cryptography
Crystal Reports
Current Affairs
Custom Controls
Cyber Security
Data Mining
Databases & DBA
Design Patterns & Practices
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
Expression Studio
F#
Files, Directory, IO
Games Programming
GDI+
General
Generative Engine Optimization (GEO)
Google Cloud
Google Development
Graphics Design
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Internet & Web
Internet of Things
Ionic
iOS
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
kotlin
Leadership
Learn .NET
LightSwitch
LINQ
Machine Learning
Microsoft 365
Microsoft Office
Microsoft Phone
Mobile Development
Multithreading
Nano Banana
NetBeans
Networking
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Power BI
Printing in C#
Products
Progressive Web Apps
Project Management
Python
Q#
QlikView
R
React
Reports using C#
Robotics & Hardware
Ruby on Rails
Salesforce
Security
Servers
SharePoint
SignalR
Silverlight
Smart Devices
Software Testing
SQL Language
SQL Server
Startups
String in C#
Swift
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
WCF
Wearables
Web Development
Web Services
Web3
Windows 10
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML Standard
XML
XNA
XSharp
Register
Login
2
Answers
unable to retrieve the hidden fields value
Kriti
15y
7.7k
0
1
Active Directory
Reply
Hey m not able to retrieve the hidden fileld(hiddenfield) value in Program.ascx.cs from Program.ascx file
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Program.ascx.cs" Inherits="a.b.c.Program" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<%@ Import namespace="System.Text" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id ="Head1" runat="server">
<script type="text/javascript">
function ConfirmIt() {
var x = confirm("Do you Want to notify changes to User ??");
var control = '<%=hiddenfield.ClientID%>';
if (x == true) {
document.getElementById(control).value = "1";
}
else {
document.getElementById(control).value = "0";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<SCRIPT language="javascript" src="js/calendar.js">
</SCRIPT>
<script event="onbeforeunload" for="window">
showWaitMessage();
</script>
<TABLE style="FONT-SIZE: xx-small; FONT-FAMILY: verdana" cellPadding="2">
<TR>
<TD>
<asp:label id="StartDate" Font-Size="XX-Small" Font-Names="Verdana" Text="Add "
Runat="server" Font-Name="Verdana">Start Date (mm/dd/yy):</asp:label></TD>
<TD>
<asp:TextBox style="TEXT-ALIGN: center" Wrap="False" MaxLength="10" id="StartDate" Height="18px"
runat="server" Width="75"></asp:TextBox></TD>
<td> </td>
<td>
<asp:label id="EndDate" Font-Size="XX-Small" Font-Names="Verdana" Text="Add: "
Runat="server" Font-Name="Verdana">End Date (mm/dd/yy):</asp:label>
</td>
<td>
<asp:TextBox id="EndDate" runat="server" Height="18px" Wrap="False" MaxLength="10" Style="TEXT-ALIGN:center"
Width="75"></asp:TextBox>
</td>
</TR>
</TABLE>
<table>
<td colSpan="3">
<asp:datagrid id="m_grid" Width="1077px" runat="server" HorizontalAlign="Center" BackColor="White"
Font-Names="Verdana" BorderStyle="None" BorderWidth="2px" BorderColor="Gray" CellPadding="3"
PageSize="20" AllowSorting="True" AutoGenerateColumns="False">
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#FFFF80"></SelectedItemStyle>
<AlternatingItemStyle BackColor="LightCyan"></AlternatingItemStyle>
<ItemStyle Font-Size="XX-Small" Font-Names="Verdana" ForeColor="#000066"></ItemStyle>
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" ForeColor="White" BorderStyle="Inset"
BorderColor="Silver" BackColor="SteelBlue"></HeaderStyle>
<Columns>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="Link" DataTextField="Number" SortExpression="Number"
HeaderText="Number">
<HeaderStyle HorizontalAlign="Center" Width="60px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn Visible="False" DataField="Pre" SortExpression="Pre"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="Pre" HeaderText="Pre?">
<HeaderStyle HorizontalAlign="Center" Width="80px"></HeaderStyle>
<ItemTemplate>
<div>
<input id="inpHide" type="hidden" runat="server" />
<asp
ropDownList id="dd" runat="server" Width="87px" Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" ForeColor="Black" onselectedindexchanged="dd_SelectedIndexChanged" onChange="ConfirmIt()" AutoPostBack="true" >
<asp:ListItem Value="Pending">Pending</asp:ListItem>
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp
ropDownList>
</div>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="Notes" SortExpression="Notes"></asp:BoundColumn>
<asp:TemplateColumn SortExpression="Notes" HeaderText="Pre_Notes">
<HeaderStyle Wrap="True" HorizontalAlign="Center" Width="100px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:TextBox id="txtNote" TextMode="MultiLine" wrap="true" Columns="30" Rows="2" runat="server" Font-Names="Verdana" Font-Size="XX-Small"></asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="State" SortExpression="State" ReadOnly="True" HeaderText="State">
<HeaderStyle HorizontalAlign="Center" Width="100px"></HeaderStyle>
</asp:BoundColumn>
</tr>
</table>
</form>
<SCRIPT language="javascript">
function showWaitMessage()
{
}
//many more functions.
</SCRIPT>
</body>
</html>
My Program.ascx.cs is
namespace a.b.c
{
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Web;
/// <summary>
///
/// </summary>
public partial class Program : System.Web.UI.UserControl
{
private string tDate = string.Empty;
#region Class Variables
//strings and variables initialization
#region GUI Components
//all gui componenets..
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.ImageButton btnRefresh;
#endregion
#endregion
#region Public Properties
public bool IsAdmin
{
}
public string SortExpression
{
}
//many public functions
#endregion
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSaveChanges.Click += new System.Web.UI.ImageClickEventHandler(this.btnSaveChanges_Click);
this.btnExcel.Click += new System.Web.UI.ImageClickEventHandler(this.btnExcel_Click);
//many more
this.Load += new System.EventHandler(this.Page_Load);
// this.ddPreApproved.SelectedIndexChanged += new System.EventHandler(this.ddPreApproved_SelectedIndexChanged);
}
#endregion
#region Public Methods
//many more public method..
public void Refresh()
{
try
{
}
catch (Exception ex)
{
}
}
#endregion
#region Private Methods
//many private functions...i have just displayed mine..I have changed private to //protected..then also its not working
private void ddPreApproved_SelectedIndexChanged(object sender, EventArgs e)
{
int DiagResult = int.Parse(inpHide.Value);
if (DiagResult == 1)
{
//Do Somthing
Response.Write("You Have Selected Ok");
}
else if (DiagResult == 0)
{
//Do somthing
Response.Write("You have Selected Cancel");
}
}
private void btnSaveChanges_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
}
#endregion
}
}
Can u think of any soln for this so that hiddenfield is retrieved..Do u think there is problem in the Program.ascx..Just check it if i have put form and div correctly... And also i have not pasted all my code but only the code that is neccessary...Here the program which i am doing goes like this..If user does any changes in the drop-downlist,It should notify to the user..For that m using hiddenfield concept but its not working ..
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Post
Reset
Cancel
Answers (
2
)
Related Discussion