473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

UserControl

I have a hidden field and a usercontrol in a webform. And
I have a button in the user control. When I click this
button I want to access the value of the hidden field on
the form by means of a client-side javascript function.

Any help is appreciated.

Thanks,
Sudhir.

Nov 17 '05 #1
2 1672
Assuming you are using a HTML hidden textbox and a HTML button here is on
way to do it.

set the id and name of the textbox to tbxHidden
add the attribute runat="server" to tbxHidden

set the id and name of the button to btnMyButton
add the attribute runat="server" to btnMyButton

save
double click the webform (this will create object references in the code)

add this line to page_load
btnMyButton.Attributes.Add("OnClick",
"javascript:myButtonClick(document.all." + tbxHidden.ClientID + ")");

javascript can look loke this

function myButtonClick(hiddenTextBox){
alert(hiddenTextBox.value);
}

if this need to run outside of IE make sure you set ID and Name also change
document.all to document.forms(0)

Hope this helps

Jamey...

"dotbet beginner" <sk*****@comsult.com> wrote in message
news:10****************************@phx.gbl...
I have a hidden field and a usercontrol in a webform. And
I have a button in the user control. When I click this
button I want to access the value of the hidden field on
the form by means of a client-side javascript function.

Any help is appreciated.

Thanks,
Sudhir.

Nov 17 '05 #2
Hi
I have a button in the user control. When I click this
button I want to access the value of the hidden field on
the form by means of a client-side javascript function.


With this code you can access the hidden field value:

HTML page:
<script language="jscript">
function getFieldValue(fieldName)
{
alert(document.forms[0].item(fieldName).value);
}
</script>

Codebehind:
private void Page_Load(object sender, System.EventArgs e)
{
this.Button1.Attributes.Add("OnClick", "javasc" +
"ript:getFieldValue('hidden')");
}

Obviously you can manage the value only in client-code.

If you want to use the value in server code you must define runat=server for
your hidden control,
therefore in the codebehind:
protected System.Web.UI.HtmlControls.HtmlInputHidden hiddenServer;

private void Page_Load(object sender, System.EventArgs e)
{
string value = hiddenServer.Value;
}

Ciao
Giorgio


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
8
by: Raed Sawalha | last post by:
Hi, I have a strange problem with a usercontrol on a page. The usercontrol dispalyes three categories (From a database) when the user clicks a category they see all the products in a shop for...
2
by: Eric Maia | last post by:
I have two UserControls I am using in a form. These are each also used separately in two other forms. The structure is essentially this: CourseUserControl.ascx - select or enter a course...
2
by: Sascha | last post by:
Hi there, I searched carefully through the web before finally deciding to post this message, because I could not find a solution for my problem. Hopefully someone will have a hint or explanation...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
5
by: Blue | last post by:
We have a custom word processing type editor built with C# and .NET 2.0 and we need to support typing in languages other than English. I want to be able to use the Windows IME to enter in text...
6
by: MeowCow | last post by:
I have created a UserControl that encapsulates a third party data grid. My goal was to create my own DataSource and DataMember properties that forward the binding to the third party grid, then use...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.