473,385 Members | 1,764 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,385 software developers and data experts.

How to call a function on run time button click

How to call a function on run time button click.

As I have created a table and a button on run time and want to call a function on its click on
code behind page(.cs page).

It is in Asp.net with c#

my code full details is like
Expand|Select|Wrap|Line Numbers
  1. strhtml = strhtml.append(<button id=btnclick, runat='server',onclick=testfunction''></button>);
2) my function is on same page like
Expand|Select|Wrap|Line Numbers
  1. testfunct()
  2. {
  3. xyz;
  4. }
  5.  
now i want to call this function on click of button
Mar 8 '10 #1
8 4529
semomaniz
210 Expert 100+
Expand|Select|Wrap|Line Numbers
  1.   Button btn = new Button();
  2.   btn.ID = "btntest";
  3.   btn.Click += new EventHandler(btn_Click);
  4.  
Mar 8 '10 #2
semomaniz
210 Expert 100+
When are you creating the control ? On page load or a a click event ?
Mar 8 '10 #3
on page load,
but have to call function on button click which is creating at run time
Mar 8 '10 #4
semomaniz
210 Expert 100+
Why dont you create a button as i mentioned before?
Mar 8 '10 #5
ok I wil give it try and
get u touch soon

thanks
Mar 8 '10 #6
Frinavale
9,735 Expert Mod 8TB
When developing in ASP.NET it is a good idea to use ASP.NET controls instead of HTML controls. The reason is because you will be able to access ASP.NET controls much more easily in your C#/VB.NET server-side code that you will be able to access HTML controls.


A good place to learn about any .NET controls (ASP.NET included) is the MSDN Library. I suggest that you go through your Toolbox to discover what ASP.NET controls are available to you before you jump straight to the MSDN Library or else you won't know what to search for.

Happy Coding,

-Frinny
Mar 9 '10 #7
hi

its ok to use asp.net controls instead of html
but what if we have to create report at run time.thats why we used html control
and dint find solution
how to call function which is on same page
( code behind page)
problem is that Im not getting click event of this button (html button )on this
page ( code behind page )


thanks
Mar 12 '10 #8
Frinavale
9,735 Expert Mod 8TB
Sachin2320,

It would be best if you described exactly what you are trying to do because right now I have no idea what's going on. No where did you mention a report...and no where did you mention why you need to dynamically create this button.

I still think that you should use an ASP.NET Button control because then you can handle it's OnClick event (server-side)...which is exactly what you are looking to do.

There is no such thing as a server-side OnClick event for an HTML button. I believe if you use the Request object you may be able to determine if the button was the thing that submitted the page...but this is overly complicated especially since the ASP.NET Button already does this for you (and creates the server-side OnClick event which you can handle).

It is a LOT easier to use an ASP.NET Button in an ASP.NET application than it is to use an HTML button....especially when you want to do something in your server code in response to clicking the button. All you have to do is Drag the Button from the Toolbox onto your ASPX page (not your C# code...your page design)...and then implement a method that handles the OnClick event for this button.

ASP.NET Buttons have a property called "Visible". If you set this property to False then this button will not be rendered as HTML and so it will not appear in the browser.

This means that you can have a button declared in your ASP.NET page, set it to Visible and it won't show up in the browser.

You can set the Button's Visible property to True and the button will be visible...you should only set this property to true when you need the button.

Dynamically creating ASP.NET buttons is not trivial and requires some thinking so this is why I'm recommending that you use the Visible property.

Now, I'm guessing that you only want to use 1 button on your page...if your report has multiple buttons in it (ie: a column of buttons) then you have to take a completely different approach and you should be using something like a GridView or a Repeater control...which will automatically, dynamically create buttons for you (with unique IDs and everything)...you can handle the dynamic button click in your server-code.

I cannot help you any further because you haven't shared with us what you are trying to do, why you need the button, where the button exists, or how many buttons need to be created.

Once you describe your project and describe why you need the button (and where it should be used) then we can help you more.

-Frinny
Mar 12 '10 #9

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

Similar topics

6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
3
by: David N | last post by:
Hi All, I just wonder if in C#, I can develop a user defined control that can call its parent function which is not yet developed. For example, how do I make my user control call a...
0
by: [Yosi] | last post by:
I search solution for a little bit strange problem , I working on an application which includes a button. Click on this button will create number of threads each one execute deferent executable...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
1
by: Bill Borg | last post by:
Hello all, Simple chat app, where the site owner has a master window with all requests for chat, status of each room, etc., and child windows for each separate chat in which the owner is...
7
by: C.Joseph Drayton | last post by:
I have a problem that I am hoping someone can help me with. First let me describe the problem. I have an HTML form that in one field has an onBlur call to a JavaScript function. When you exit the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.