473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnServerClick not taking an argument

16 New Member
HI All,

I am having a client side code :

Expand|Select|Wrap|Line Numbers
  1. <asp:HiddenField ID="hiddenfield1" runat="server" Value='<%# Eval("Id") %>' />
  2. <a runat="server" id="hlViewPropertyAddressDetail" onserverclick="logstats(hiddenfield1)">
and in the Code Behind i have a logstats function as
Expand|Select|Wrap|Line Numbers
  1. public void logstats(string id)
  2. {
  3. ....
  4. .
  5. .
  6. .
  7. .
  8. }
I am getting an error which says hiddenfield1 does not exist in current context, for the onclicksrrver event.
CAn anyone help me with the error.
Many Thanks,
Bh
Jan 12 '09 #1
6 10011
Frinavale
9,735 Recognized Expert Moderator Expert
Your HiddenField is an ASP.NET control.
When it is rendered in the browser it may contain a different name than what you have typed. You are attempting to call Server Side code from an HTML hyperlink...pas sing that code a String... I don't understand what you are trying to do.

What are you trying to do because the code you have posted isn't making sense?

I would recommend using a LinkButton instead of an HTML "<a>" link since you want to execute Server Side code when the link is called. I think this would solve all of your problems.
Jan 12 '09 #2
shweta123
692 Recognized Expert Contributor
Hi,

In order to remove the error that you are getting please make the following modification in the code :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="c#" runat="server"> 
  3. void click(Object s, EventArgs e) 
  4. {
  5.   //call required function on the click of hyperlink
  6.    logstats("hiddenfield1");
  7.  
  8.  
  9. public void logstats(string id)
  10. {
  11.   //code for this function
  12. }
  13. </script>
  14.  
Now you can call the click function onserverclick of hyperlink control.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <a runat="server" id="hlViewPropertyAddressDetail" onserverclick="click"/>
  4.  
Jan 12 '09 #3
Bhavs
16 New Member
Thanks Shwetha,

I am using the same solution now.
But the problem is finding the value of the Hiddenfield control. As the hidden field is inside a repeater.

I am using
Hidden Field hide = (Hidden Field)Repeater. FindControl("hi ddenfield1
]but I am geeting the value as null
Is ther any way to retrive a Hidden Field value placed inside a Repeater control??
Jan 13 '09 #4
liawcv
33 New Member
Let make the concept right: A Repeater maintains a RepeaterItemCol lection which contains 0 or many RepeaterItem. And each RepeaterItem is created / rendered based on the <ItemTemplate > that we defined in the .aspx file.

Let assume that we have a Repeater with a simple structure as:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater runat="server" ID="Repeater1" ...>
  2. <ItemTemplate>
  3.    <asp:Label runat="server" ID="Label1" ... />
  4. </ItemTemplate>
  5. </asp:Repeater>
  6.  
During runtime, depends on the data source, there may have 0 or many Label1 being generated in the Repeater. For this reason, the following line is not work:

Repeater1.FindC ontrol("Label1" );

Firstly, there are many Label1, ASP.NET doesn't know which Label1 we are asking for. Secondly, THE CONTEXT IS JUST NOT RIGHT! That's why you get a null all of the time.

Recall that all RepeaterItem are maintained under the Repeater's RepaterItemColl ection, and our Label1 is in fact a control under its particular RepeaterItem. So, the hierarchy would be:

Repeater --> RepeaterItemCol lection --> RepeaterItem --> Label1

Back to the example: In order to find Label1 in the 1st RepeaterItem, we should do this:

Repeater1.Items[0].FindControl("L abel1");

In order to retrieve all the Label1's Text, we should do this:

Expand|Select|Wrap|Line Numbers
  1. Label lbl;
  2. foreach(RepeaterItem i in Repeater1.Items)
  3. {
  4.    lbl = (Label)i.FindControl("Label1");
  5.    Response.Write(lbl.Text + "<br />");
  6. }
  7.  
So, the key point is THE CONTEXT. I didn't really answer your question. But hope this could help you to understand "where is the right place" to find your HiddenField.

By the way, I am wondering how you would know the right RepeaterItem index so that you can find the exact HiddenField that you want, out of many other HiddenFields in your Repeater.

Consider to use LinkButton and Repeater's ItemCommand event if you still can't get your problem solved.
Jan 13 '09 #5
liawcv
33 New Member
Let me guess: The purpose of your HiddenField is to hold the Id so that your logstats() function is able to figure out which Id to be processed. And your <a> is to provide an hypertext-liked interface to the user, so when it is clicked, the longstats() function will be called.

If my guess is right, then let me give you few suggestions here:

1. Remove your HiddenField
It makes the job of getting the correct Id more troublesome only. There are better methods available to encapsulate the Id value in the button itself.

2. Replace your <a> with LinkButton
Practice: In ASP.NET, it is advisable to use standard Web Control whenever you want to access to the control programmaticall y. CommandArgument: As mentioned, it is easier if the Id is encapsulated in the button itself. CommandArgument property serves the purpose. Somehow, <a> doesn't have this property.

How to make this work? The Repeater should now look like this:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="Repeater1" runat="server" ...>
  2.    <ItemTemplate>
  3.       ...
  4.       <asp:LinkButton runat="server" ID="LinkButton1"
  5.          Text="LinkButton Text"
  6.          CommandArgument='<%# Eval("Id") %>'
  7.          OnClick="LinkButton1_Click" />
  8.       ...
  9.    </ItemTemplate>
  10. </asp:Repeater>
  11.  
And LinkButton1_Cli ck event handler is to be created in your code-behind file:

Expand|Select|Wrap|Line Numbers
  1. protected void LinkButton1_Click(object sender, EventArgs e)
  2. {
  3.    // And you get your Id with this line
  4.    string id = ((LinkButton)sender).CommandArgument;
  5.    ...
  6. }
  7.  
Simpler?
Jan 13 '09 #6
Bhavs
16 New Member
Thanks Liawcv.

I am now using the for each loop to fetch the value of the hidden field.
The reason I am using a anchor control is I have to display a hyper link statement( and on clicking on this hyper link I need to take the control to log method)

I have now got a better understanding about the repeaters. Thanks again.
Jan 14 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

13
1853
by: Ideasman | last post by:
Hi I have a made a script that process normals for a flat shaded 3D mesh's. It compares every vert with every other vert to look for verts that can share normals and It takes ages. I'm not asking anyone to rewrite the script- just have a look for any stupid errors that might be sucking up time.
2
2909
by: ishekar | last post by:
Hi, I have a class which has only one constructor that takes an argument. I want the users of this class to pass the parameter in the declaration. The problem i am facing is this cannot be used in the declaration section. is there any work around. thanks ishekar.
9
5063
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar = getter(file); What type should I give to `getter' so that the compiler does not issue
1
6465
by: Krishna | last post by:
1. What is the difference between OnClick and OnServerClick in web button control If I have a asp button control as follows <asp:button id="SubmitOrder" Text="Submit Order" OnClick="OnSubmit_Click()" runat="server" > </asp:button> If the above is going to fire server side function what is
7
1459
by: Robert Blackwell | last post by:
Hey, I have a question for you web devs out there. How much of a hassle is it to take over where another programmer left off. I have a commerce site that was designed to my specs and I approached the company to do some upgrade work on it. However, I'm canceling the project with them because they are basically accusing me of scope creeping even though my specifications clearly define the features I am asking them to correct. I asked them...
3
5076
by: Kristian Frost | last post by:
Hi, me again, I'm trying to create a User Control in VS2003 that takes an object as an argument from its parent form and designs itself accordingly. At the moment, I'm having to create a default, empty constructor method and then adjust the size later by sending in the argument in a later method and then resizing everything, instead of simply creating things according to these arguments in the first place. Obviously, seeing as the whole...
3
2097
by: John Shell | last post by:
Hello, all. The following code results in a C2666 error (2 overloads have similar conversions). class FSVec2D { public: FSVec2D() { // code omitted }
18
3207
by: mamul | last post by:
Hi, Please help me. I want to create a function taking file as an argument and open that file in the browser. wfstream file_stream; void function(string filepath) {
4
7119
by: James Kanze | last post by:
On Nov 18, 5:50 pm, Pete Becker <p...@versatilecoding.comwrote: Has this changed in the latest draft. According to my copy of the standard (version 1998---out of date, I know), "The operand shall be an lvalue or a qualified-id". His expression was &Test("test2"); IMHO, the compiler generated a warning because it was being laxist.
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.