.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

C# Run onlick method in .cs code from href button

Posted By:      Posted Date: October 17, 2010    Points: 0   Category :ASP.Net

I have a css style button that is calling a method in the .cs file

loggut_Click is the method in the .cs file that button is gonna run

From the .... .aspx file

<a class="brochure" href="#" runat="server"><span>Logg ut</span>

have tried changing out the # with onclick="loggut_Click" but its still not working.

from the ....cs file 

protected void loggut_Click(object sender, EventArgs e)
Session["Innlogget"] = "nei";

Any suggestion on how to do this? All this button is gonna do is actually just set the Session "Innlogget" to "nei" as in you are not logged inn anymore. 

View Complete Post

More Related Resource Links

Button specific code


I have 2 submit buttons on my page. Right now, the only way to run the code behind with razor is to to If(IsPost). Since I have 2 buttons, how would I destinguish between the two in post? Is there a way to request a button that sent a post request?  

Infopath button click event in custom workflow code.


Hi All,

I have designed the infopath form(Init) and integrated with my state machine workflow. i want to access button click event (designed in Infopath form) in my workflow code.

Can you help me.




Control this objectdatasource programatically from the code behind based on different button clicks

I have a page where you can search and display other data, very simple layout. 1 Gridview and 1 objectdatasource. But i have 4 possible buttons that can populate the gridview.. i would like to control my objectdatasource from the code behind based on the button you click. here is what i have right now.. but if possible, can this source not be hardcoded like this and only built in the code behind? <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectDVRInfo" TypeName="DataAccessCode"> <SelectParameters> <asp:ControlParameter ControlID="ddlDVR" Name="dvrInfo" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:ObjectDataSource> I found this site with a solution to this persons issue, but i cant seem to get mine working this way. http://stackoverflow.com/questions/2404264/overwriting-controlparameters-of-datasources-in-code-behind I have  this as the code behind right now when you press the button.. what other parameter settings am i missing and is this the right order to populate them for the source to acknowledge my values?   ObjectDataSource1.SelectMethod = "SelectDVRInfo"; ObjectDataSource1.SelectParameters["MyParameter"]

Code Behind (C#) - Postback - "If (this button was clicked) postback to this address, otherwise, do

Hello!!I have three buttons at the bottom of my form. Two of the buttons make the form invisible and make a Success message Visible.I need all three buttons to call SubmitForm Function to send us an email with the completed form.The third button is a PayPal button which I would like to postback to a different url after submitting the form via email.How can I change its Postback url in C# in the code behind.P.S. I tried Server.Transfer... got an errorThanks

Dynamic method creation using code snippet

Hello, I am looking to map a method from php to .NET. There are various methods I am targeting, and most don't satisfy a one method-to-one method conversion; alot of the mapping really requires a few lines of logic thrown in, and not just "this .NET function call for this php function call." Anyway, I've defined the mappings as strings, and all I need to do is plug them into a dynamic method that will create, run the code, and return the appropriate value. I do not want to create an assembly in the process, which I think leaves CodeDomProvider out of it. And I don't want to generate my code in IL, which I think leaves MethodBuilder and DynamicMethod out of the running. Can anyone lead me in the right direction here? Is there a way to do what I am asking?   Thanks!

Print Button +code in form

Using sharepoint 2010 and designed a simple form. How can I add the Print functionality to the ribbon from standard SP2010 NOT using Infopath? thx

Why request parameter added to client side code in each method while using svcutil.exe

Hi, I am using WCF services in my project and want to call WCF methods asynchronously. I am hosting WCF service programmatically in windows app as follows svc = New ServiceHost(GetType(Service1), New Uri("net.tcp://localhost:8806/")) Dim svcMDB As New ServiceMetadataBehavior svc.Description.Behaviors.Add(svcMDB) svc.AddServiceEndpoint(GetType(Service1), New NetTcpBinding(), "MyBusiness/MyBusinessService/") svc.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexTcpBinding(), "MyBusiness/MyBusinessService/mex") svc.Open() Me.Text = "Service started...." and I am generating client side proxy using svcutil.exe as follows. svcutil /n:net.tcp://localhost:8806/MyBusiness/MyBusinessService,MyService net.tcp://localhost:8806/MyBusiness/MyBusinessService/mex /a /language:vb   The result of this command is as :   Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152] Copyright (c) Microsoft Corporation.  All rights reserved.   Attempting to download metadata from 'net.tcp://localhost:8806/MyBusiness/MyBusi nessService/mex' using WS-Metadata Exchange. This URL does not support DISCO. Generating files... D:\Prabodh\New C2k\Test Projects\DataTableToArray\MyHost\bin\Debug\MyBusinessSer vice.vb D:

Enable a button based on a list via code behind


I've got a ListView with textboxes inside (bound to a property) and a button behind it.

I'd like to make the button enabled only when:

1) Each TextBox is not empty (each property has got a value)

2) Each TextBox has not got errors

How can I do it via code behind?


MOSS 2007 - Error Code 500 after click on Ok button on a post reply with an accent charactere in the



I have this strange behavior in my test and prod environment but not in my Dev.

The case is as following:

  1. Someone create in a discssion list a topic with an accent charactere in the title.
  2. Someone else click on the reply button. then he write the post.
  3. Then he click on the Ok button and a code error 500 page is loaded.

In the same discussion list If the title of the topic does'nt contain any accent charactere it works well !

Regional settings of the site collection are strictly identical on Dev, test and pro environment.

Does someone have any Idea ?

Thanks in advance for your answers



No OnClick-events on any button/ImageButtons on any page runs any code




I Simply drag a button from the toolbar onto a new page with a master page and a title, double click it so that I enter the Button1_Click function and sets a breakpoint and add some random code. The breakpoint nor the code never fires. I've tried this on several different pages and controllers, but with the same results: The page reloads, but no code is run.

I Have Tried:

Ive tried with three different webbrowsers with all plugins disabled.

I've tried to turn of Causes Validation, - Nothing changes.

I've tried to clean and Rebuild the project, - Still nothing.

I've tried to create a whole new project, - Does'nt work there either.

Other Information:

A RadioButtonList OnDatabound Event works, but whenever i try to do a Button or ImageButton click event the code for the event never fires. Ive programmed several webapplications in other versions of visual studio and ASP.NET but I have never encountered this problem before.

Breakpoints work in other parts of the code and the compile settings is set to DEBUG.


I am using

* Visual Studio 2010


* MVC 2.

Am I supposed to file a bug report or does anyone out there have a solution?

Many thanks in adv

error code:0xC0024104 source: Reporting Task for subplan- Description: the execute method on the tas


I am getting following error when running maintenance plan under schedule job. I am getting this error for maintenance cleanup task.  The job is not failing all the time but alternate weeks. I created same maintenance plan on test server(same configuration as PROD) and Maintenance cleanup task related job failed for first time and running fine from there. I don't know why it is causing failed. I checked maintenance plan history and it show successful each time. even i checked manually it deleted all the report files related to maintenance plan. History Cleanup task and Maintenance Cleanup task should not be created on same Maintenance Plan?....I know SQL Server 2005 had some problem with maintenance plan creation before SP2.

Calling Button,s onclick event in javascript code


 Hi Experts.

I have a Button control in webpage.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="test()"/>

When i click on button, i want to check some conditions



I have a package that connects to IBM DB2 and imports data and saves it into text files.There are around 200 txt files. am using IBM OLEDB provider for DB2. After importing data into some text files like may be 50 or 70 or 100 or 170 , my package fails with error

SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager  failed with error code 0xC0202009.

help needed plz...

No "Edit Form Code" in Button Properties box.


Using InfoPath 2007. VSTA is installed. Also have VS 2008.

Want to test button onClick, but when I double click but in form design, I don't have the "Edit Form Code" button.

ALT-SHT-F12 opens VSTA, but no code automatically added for the onCLick event like it would be with Edit Form Code button.

Any suggestions or explanation why I can't see it?

How "press" a WPF button from within code?


How do I simulate the press of a WPF button from within code? I would like to call a method from within my code and have a particular button on a WPF form look like (visually behave like) it had been pressed and released (and presumably also fire its click event). I seem to recall doing this years ago with win forms and VB. Thanks!

Why? I have a form with several buttons and some keyboard shortcuts for those buttons. When a user presses the appropriate key, I would like to provide visual feedback that the key that was pressed was equivalent to a particular button.

calling a code behind method using xaml?


Is it possible to call a method in a XAML's code-behind through XAML itself? ie:

<Image Source="{Binding GetRandomImagePath}" />


public string GetRandomImagePath(...){////}


InternalStartup method erro when publish InfoPath form with custom code


Hi All,

I created a SharePoint Form Library, and added a button in the form. Then, by following the steps of adding custom code. I was trying to add codes to the button click event in VSTA. When I try to publish this form to my SharePoint library, I got an error message say:

"The form template has been published to the server but it can only be opened in InfoPath Filler.

There is an error in the InternalStartup method of form code.

There may be additional error detials in the Design Checker task pane."

However, I did not make any changes to the InternalStartup. and then I tried to create another SharePoint Form Library Form in InfoPath Designer, and just add click event, but did not input any code, I got the same error. So I believe this is caused by either environment or the configuration of SharePoint Server. Could anyone help me out? Thanks!

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend