tags:

views:

10

answers:

2

Hi,

I had created a simple web part with one label, and one button. I wnat that when i click the button the label content will change. But when i debugg i found that the focus is not going inside the Button Click Event function. When i click the button the debugger will again start with page load. Is there any Autofocus for Button. Please help me to resolve my problem.

Thanks :)

A: 

I think that you're confused about what happens on the client (within the browser) and what happens on the server (in your ASP.NET code).

Most events on server-side controls, like the ASP.NET button, are handled server-side, through a mechanism called postback. The generated code on the browser causes a form submit to the Web server, where the page and its controls are re-created. The form data is parsed and the button control generates (in your case) a Click event for your server-side code. This code regenerates a new HTML page which will replace the old one.

Fortunately for you in this case, the ASP.NET button has a property "OnClientClick" where you can insert JavaScript code to do whatever you want (like change the label text) directly in the browser.

See MSDN for the docs on the property and an example of using both Click and OnClientClick.

Note that this is not related to SharePoint, this is a pure ASP.NET issue.

Timores
A: 

Hi, Thanks for replying. Can you please suggest me any link from where i can get the basic example for creating the web part with button example

Manjeet Singh