C# .NET need button to fire without fire page load event

I have a asp.net button on my form. I need to fire click event of button without firing page load event of page. Anybody know what the trick is?


Thanks in advance.
0
nitesh
8/26/2004 5:04:37 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
4673 Views

Similar Articles

[PageSpeed] 12
Get it on Google Play
Get it on Apple App Store

Hi there!

Then you shouldn't use the asp.net's WebControls.Button but instead use normal html button because WebControls.Button always fires the post-back.
You must use a javascript function to do something when the button is clicked.
<input type="button" value="Click me!" onclick="Clicked();">

....
//Then you must have a function "Clicked()":
<script language="javascript">
function Clicked()
{
alert('Button clicked!');
}
</script>

Like this. If you want to affect the button's params or UI from the server-side code, you just add the "id" and "runat" params to the button. Html button has two different click event types if it is declared as an asp.net html control (means it is normal html control with id and runat tags). Onclick event is called on the client-side (javascript etc. function) and if OnServerClick event is declared, the button fires the post-back and the server-side method which is given to the event is fired.
I hope you understood me. :) Please feel free to ask more.

Arto Kainu

BScEng

Joensuu, Finland
0
LoorD
8/26/2004 7:06:16 AM
Page_Load event executes on each roundtrip. Why would you want to do it? May be the soulution for you is to move code from Page_Load to another function and call it on conditions?
Leon Langleyben

MCSD, ASP.NET MVP

Blog
0
llangleyben
8/26/2004 7:09:08 AM


All server controls that cause the page to post back will cause the page_load event to execute. The page class goes through the same life cycle on each request.
If there is code inside you page_load event handler that should not execute when the page is posted back from a button click event, check the PostBack property of the page:

If Not Page.IsPostBack Then
'execute this code
End If

You can use the IsPostBack property in other event handlers also, such as Page_Init, and Page_PreRender, and so on.

Jamie Kindred, CGA, MCSD
1
NetProfit
8/26/2004 11:48:38 AM
Sorry, wrong language:


if(!Page.IsPostBack){
//execute this code
}


Jamie Kindred, CGA, MCSD
0
NetProfit
8/26/2004 12:20:44 PM
Reply:

Similar Artilces:

How to prevent page load event from firing on any other event fired.
Hi to all, I m creating controls dynamically on page load event but now what problem i m facing is that after page load event fired once when i m clicking submit button then page load fires again and it changes the value of  controls. so now can anyone tell me how can I prevent page load event to fire on any other event. Please answer me. Thanx in advance.   To stop a control from doing a postback, you can set it's AutoPostBack property to false. To avoid re-initializing code on postbacks: protected void Page_Load(object sender, EventArgs e) { if (IsPostBack ...

Getting The Event's Name Fired In Page.Load Event Handler
Hi,How to get the event's name / type that is fired in Page.Load event handler? I'm trying to create an exceptional procedure in Page.Load event handler when some certain events are fired.Thanks in advance  i think you can try this code and modify it yor requirnment Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack = True ThenMe.Label1.Text = Me.Page.Request.Params.Get("__EVENTTARGET")  Dim ctrlname As String = Page.Request.Params.Get("__EVENTTARGET") If (Not ctrlname Is Nothing And ctrlnam...

Using a user control 2 times on a page: first one fires all events, second one fires all events but not 4 buttons
Hello!Edit solved:The problem was that depending on the databind i didn't add the buttons to the control tree instead of simple set visible to false. This worked fine for the first user control cause databinding was triggered on Page_Load but for the secon one the databidning took place later on so the condition not to add the buttons to the control tree set in. The simple solution was to always add the buttons to the control  tree and then check on Pre_render if the visaibility had to be set to false.So always keep in ind:1) Add controls to the control tree for the postback ev...

Master Page's Page Load firing twice on events called from other Page events
I have numerous pages tied to my MasterPage that controls 2 Always visible extenders for User Reminders and a Counter. I would like them to only fire on a Page_Load once, not twice. I have read a million posts about AutoEventWireupset to false, but on all my pages it is set to true and on those pages the events only fire once. The Master page is giving me problems on events firing twice. Any suggestions? here is some code... protected void Page_Load(object sender, EventArgs e) {if (!Page.Master.IsPostBack) {  I call 2 stored procedures here that should only fire once on a Page_Lo...

Can I determine in page load or data load, if a item command was fired. Event expert needed.
My question is how can I determine in page load or data load, if a item command was fired.   These events occur before itemcommand!  Here is the situation.  On a datagrid is a link button that posts back, issues and item command to move to another page.  I want the redirect to occur on the postback  and not on the client side. The problem is that the query to load the datagrid is slow.  The event order is to do a page load, then the data load for the grid, and THEN the item commend.  Since I don't care about showing the grid again when the l...

Button event getting fired when page is refreshed
Hi, I have a peculiar problem which is understandable also. I have put some text controls to capture user input. I have an insert button on a web form. In the insert button click i am adding the details to a dataset and dynamically binding it to a DataGrid in the same page. When I click the first time everything is working fine and the details get added to the datagrid. However when I click the refresh button, the same event is getting fired and the details are getting added to the dataset and in turn to the datagrid again. I want to avoid this problem. Same is the ca...

How other Events fire before page load events
Hi all,  In my application, I have a gridview in update panel. I have set link buttons for first, previous, next and last. Set page size of gridview as 5. Gridview have Row_Created and Data_Bound event. When I started to debug first time it goes in page load event. But when I clicked on last button of gridview it directly goes to gridview's event and not in page load event. Why this happened? Please tell me solution. niteensapkal:But when I clicked on last button of gridview it directly goes to gridview's event and not in page load event. it should... if last butt...

Page_Load not firing after moving page from VB.NET to C#
  The page and code-behind are working just fine once I correct the event firing differences for C#, but I cannot get even this:         protected void Page_Load(object sender, EventArgs e)        {                       this.Text1.Text="ACK????";        }    To fire on load. I've checked for everything I know of to make this work as the default ...

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Button event getting fired second time when page is refreshed
Hi, I have a peculiar problem which is understandable also. I have put some text controls to capture user input. I have an insert button on a web form. In the insert button click i am adding the details to a dataset and dynamically binding it to a DataGrid in the same page. When I click the first time everything is working fine and the details get added to the datagrid. However when I click the refresh button, the same event is getting fired and the details are getting added to the dataset and in turn to the datagrid again. I want to avoid this problem. Same i...

Button event is not firing in ascx control when loaded on aspx page
 Hi, I used code like this for Dynamically  loading usercontrol in aspx page.             Control uc1 = LoadControl("Users/userdetails.ascx");            PlaceHolder1.Controls.Add(uc1); But in userdetails.ascx page i have "Submit" button when i Click on button it was not firing.please any one help me why it was happening,suggest me how to solve this problem. Thanks in Advance Hi,in which event do you add your usercontrol? Because you can run into ...

On enter
 I'm using .net 1.1. My content page is inside a template. There is a submit button in the template and in my page. When the user presses enter key, the button click event in the template page is firing. How do I force my button click event to fire on enter? I googled it and found a fix that if I add an input control it should fix it. But it didn't. Are there any other solutions? Here is my page's code. i don't have the template code.<form runat="server" id="FormDonor" method="post">          &nb...

C# .Net
Hi guys, hoping that someone may be able to help on this. Basically I have a C# .Net webpage, that has a listbox with dynamic data (called from a webservice) - I want to populate a few textboxes with the selected Listbox data. When the listbox is populated with multiple results, everything works great (clicking an item the "SelectIndexChanged" event is fired), but this does not work if there is only 1 record in the listbox. How can I handle this? Thanks Phil I can suggest that you manually add a general "Select" item to the list which will force them to make a selecti...

User control image button event not firing on first page load
Hello, I have a page (Parent.aspx) with a panel on it. In the panel, I dynamically load user controls (Child.ascx). The first time I click on the image button on Child.ascx, the following events happen: 1. Page_Load for Parent.aspx fires. Here, I reload Child.ascx. 2. Page_Load for Child.ascx fires.   Any subsequent clicks of the image button on Child.ascx triggers the following: 1. Page_Load for Parent.aspx fires. Here, I reload Child.ascx. 2. Page_Load for Child.ascx fires. 3. ImageButton_Click fires.   Obviously, I would like the ImageButton_Click sub to fire the firs...

Web resources about - C# .NET need button to fire without fire page load event - asp.net.getting-started

Police hunt for murder weapon after business woman, 60, is stabbed to death in ‘ferocious and targeted ...
Police search teams upped their investigation into the murder of businesswoman Sadie Hartley (pictured) today as they searched rivers, walks ...

Could ‘Making a Murderer’ Return for Season 2?
After his executive session, Netflix Chief Content Officer Ted Sarandos addressed the popularity of Making a Murderer and the demand for a follow-up ...

Amy Schumer in white Calvin Klein at the Critics’ Choice: beachy or too plain?
Amy Schumer was presented with the MVP Award last night by her mentor, Judd Apatow, who joked that they made up an award just to get her there. ...

UK Parliament to Formally Debate Banning Donald Trump Today
UK’s Parliament will formally debate banning Donald Trump from the country over his remarks about Muslims after a petition calling for him to ...

Dr. King's Dream
I Have a Dream [ Voices singing "We Shall Overcome." ] Intro: At this time, I have the honor to present to you the moral leader of our nation. ...

Why the Carolina Panthers can beat the Arizona Cardinals in NFC title game
Three reasons why the Carolina Panthers can beat the Arizona Cardinals in next Sunday's NFC Championship Game.

Mali and Burkina Faso join forces against attackers
OUAGADOUGOU, Burkina Faso (AP) — A Mali official says his country will work with Burkina Faso to fight Islamic extremism in West Africa.

Microsoft is working with some of its biggest partners to kill Windows 7 and 8
Microsoft is working with Intel, AMD, nVidia, and Qualcomm to support Windows 10 at a chipset level, effectively killing the future of Windows ...

How an algorithm helped global tennis match-fixing investigation
Buzzfeed’s John Templon has just unveiled 15 months of hard investigative work conducted with the BBC that reveals possible match-fixing at the ...

WhatsApp drops annual fee and goes free forever
Facebook’s WhatsApp instant messaging app for iPhone , Android and many other platforms including the web, is going free of charge, the company ...

Resources last updated: 1/18/2016 2:51:39 PM