Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Thursday, March 29, 2012

Newbie : Adding an onclick event to server control, prevents postback.??

Hi,

I have a .net page that basically has two buttons on it. Each
button when
rendered by the server basically seem to have a type of "SUBMIT". What
i want is to be able to disable one of the buttons when a user clicks
on it and have the server process the operation and then renable it
went it's done.

I added the following piece of code to my Page_Load event.

MyButton.Attributes.Add("onclick", "this.disabled=true;");

This worked fine except that my event handler in the code-behind,
ExportButton_Click is not fired and so nothign happens except for the
button being disabled. Can someone give me detailed information on how
this can be done as I'm relatively new to C# , Javascript and .Net.

I was reading about the RegisterOnSubmit statement and such but it
did not
seem to work. What am I missing? What is an easy way to accomplish
this?

Code snippets/ links much appreaciated.

Thanksyes this is a problem.
one way around this is to hide the button instead.
if looks a bit stupid but you could have a disabled button which is hidden
until you click and hide the real button.
a bit mickey mouse but what can you do?

if you find a better way, please post it.
a

"Dr Deadpan" <drdeadpan@.yahoo.com> wrote in message
news:a944d23e.0311201528.32794f68@.posting.google.c om...
> Hi,
> I have a .net page that basically has two buttons on it. Each
> button when
> rendered by the server basically seem to have a type of "SUBMIT". What
> i want is to be able to disable one of the buttons when a user clicks
> on it and have the server process the operation and then renable it
> went it's done.
> I added the following piece of code to my Page_Load event.
> MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the code-behind,
> ExportButton_Click is not fired and so nothign happens except for the
> button being disabled. Can someone give me detailed information on how
> this can be done as I'm relatively new to C# , Javascript and .Net.
> I was reading about the RegisterOnSubmit statement and such but it
> did not
> seem to work. What am I missing? What is an easy way to accomplish
> this?
> Code snippets/ links much appreaciated.
> Thanks
Instead of adding an "onClick" attribute to the button,
why not just disable it from the buttons click event?
ie. myButton.Enabled = False

I guess what you are trying to achieve is to prevent the
user from clicking the button more than once.
You should also make sure you have wired up your event
handlers for the button.

eg. protected WithEvents btnMyButton As Button

protected sub btnMyButton_Click() Handles btnMyButton.Click
end sub

This is VB code, but you need to make sure you declare
your button using 'WithEvent', and wire up the proper
event (using the 'Handles' statement) to the method that
will be handling the event.

It might also be a good idea to set the AutoEventWireup
directive in your .aspx page to False, otherwise your
event will fire twice.

Hope this helps

>--Original Message--
>Hi,
> I have a .net page that basically has two buttons on
it. Each
>button when
>rendered by the server basically seem to have a type
of "SUBMIT". What
>i want is to be able to disable one of the buttons when a
user clicks
>on it and have the server process the operation and then
renable it
>went it's done.
> I added the following piece of code to my Page_Load
event.
>MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the
code-behind,
>ExportButton_Click is not fired and so nothign happens
except for the
>button being disabled. Can someone give me detailed
information on how
>this can be done as I'm relatively new to C# , Javascript
and .Net.
> I was reading about the RegisterOnSubmit statement and
such but it
>did not
>seem to work. What am I missing? What is an easy way to
accomplish
>this?
> Code snippets/ links much appreaciated.
>Thanks
>.
"Rory" <anonymous@.discussions.microsoft.com> wrote in message news:<069e01c3aff6$1699ce20$a401280a@.phx.gbl>...
> Instead of adding an "onClick" attribute to the button,
> why not just disable it from the buttons click event?
> ie. myButton.Enabled = False

I cannot do this as it won't work. What the above will do, is disable
the button once it gets bakc to the client. All the while while the
server is actually running the code in the event handler, the button
will remain Enabled and will become disabled once the code behind is
done - definitely not what I wnat. I read a post earlier on about
doing it an easier way somewhere.
Please, all you guru's , keep the comments coming..

DrD

Monday, March 26, 2012

Newbie ?: Force a periodic postback?

Hopefully this will be an easy question, newbie here.

Is there a simple way to force a periodic postback to a page? I want to
simulate a picture slideshow and every five seconds (or so) want to cycle
the web control image from one picture to another.

I've tried doing a timer control (doesn't refresh thepage) and playing
around with META/REFRESH (causes a totally new load of the page) and was
thinking about generating some dynamic <script> code, but that just seems a
little daunting ....

Any help would be appreciated.

thanks in advance,
PatrickHi,

if you want just to farce postback you have to use DHTML and java script
to submit form (buttons) or call __postback function periodically.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Friday, March 16, 2012

newbie postback question about ASP controls

Do I understand correctly that my aspx webpage's DataGrid, Button and web
control states are somehow stored in the "_VIEWSTATE" hidden input value,
making it unneccesary to recreate their content in the case of page
postbacks? Or are there gotchas I need to look out for in assuming these
controls will work correctly, and have their former values available, after
a postback?
Thanks,
JimHi Jim,
You are correct for your server controls. The ones that start <asp:...>.
You can also add your HTML control to the _VIEWSTATE by giving them the
runat="Server" attribute. For example: <input type="hidden" id="hidValue"
runat="server"> will add this control to view state and it will retain its
value between postbacks. Good luck! Ken.
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
"Jim Bancroft" <bobgambles@.nowhere.com> wrote in message
news:epGzj$koEHA.3668@.TK2MSFTNGP15.phx.gbl...
> Do I understand correctly that my aspx webpage's DataGrid, Button and web
> control states are somehow stored in the "_VIEWSTATE" hidden input value,
> making it unneccesary to recreate their content in the case of page
> postbacks? Or are there gotchas I need to look out for in assuming these
> controls will work correctly, and have their former values available,
after
> a postback?
> Thanks,
> Jim
>
Thanks for the explanation and help, Ken! Good stuff below.
-Jim
"Ken Dopierala Jr." <kdopierala2@.wi.rr.com> wrote in message
news:%23FEbSHloEHA.2864@.TK2MSFTNGP12.phx.gbl...
> Hi Jim,
> You are correct for your server controls. The ones that start <asp:...>.
> You can also add your HTML control to the _VIEWSTATE by giving them the
> runat="Server" attribute. For example: <input type="hidden"
id="hidValue"
> runat="server"> will add this control to view state and it will retain its
> value between postbacks. Good luck! Ken.
> --