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

does asp.net provide a solution to post back from javascript to raise an server-side event in the page?

i want to raise an event on the server with a javascript call on the client.
i found a solution but i think its not so elegant. the solution is:
i call __doPostBack("RefreshPage", ""); from javascript and check in the
Page_Load routine :
bool refreshPage = Request.Form["__EVENTTARGET"] == "RefreshPage";

i could do it with __doPostBack("", "RefreshPage"); and ["__EVENTARGUMENT"]
== "RefreshPage"

i could also add a hidden input control to the form, and set its value to
something and check its value in the Page_Load event handler..

i also tried
Page.GetPostBackEventReference(this, "RefreshPage");

it writes out : __doPostBack("", "RefreshPage");

i called that function in javascript to cause an postback and in the page i
overrode the RaisePostBackEvent method:

protected override void RaisePostBackEvent(IPostBackEventHandler
sourceControl, string eventArgument)

{

if(eventArgument == "RefreshPage")

{

//Do something..

}

base.RaisePostBackEvent (sourceControl, eventArgument);

}

but this method doesnt be called by the asp.net..

it is suprising that no elegant solution is provided by microsoft. does
anybody know better way doing this?
Nov 19 '05 #1
2 4350
It's not that it's MS "not providing an elegant solution", its just that you
are dealing with apples and oranges....
Anyway, you're really pretty much on the right track. You'll have to force
the page to do a postback and catch some variable/value and manually fire
your event.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"The Crow" wrote:
i want to raise an event on the server with a javascript call on the client.
i found a solution but i think its not so elegant. the solution is:
i call __doPostBack("RefreshPage", ""); from javascript and check in the
Page_Load routine :
bool refreshPage = Request.Form["__EVENTTARGET"] == "RefreshPage";

i could do it with __doPostBack("", "RefreshPage"); and ["__EVENTARGUMENT"]
== "RefreshPage"

i could also add a hidden input control to the form, and set its value to
something and check its value in the Page_Load event handler..

i also tried
Page.GetPostBackEventReference(this, "RefreshPage");

it writes out : __doPostBack("", "RefreshPage");

i called that function in javascript to cause an postback and in the page i
overrode the RaisePostBackEvent method:

protected override void RaisePostBackEvent(IPostBackEventHandler
sourceControl, string eventArgument)

{

if(eventArgument == "RefreshPage")

{

//Do something..

}

base.RaisePostBackEvent (sourceControl, eventArgument);

}

but this method doesnt be called by the asp.net..

it is suprising that no elegant solution is provided by microsoft. does
anybody know better way doing this?

Nov 19 '05 #2
i cant see apples and oranges around what do you mean? and why
raisepostbackevent doesnt raise? if it wont raise, why Page class expose
that method? i know it raises when for example i inherit from button, i
expect same thing when i inherit from page, because its a control too.
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
3
by: Duane Phillips | last post by:
Greetings. Can an app be developed in .Net to deploy like local installed apps, and then later reuse that code and object set to deploy on a web server? I have read a little about WEB vs. RICH...
16
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen...
6
by: Henri | last post by:
Very strange problem : if I write: <asp:TextBox runat="server" id="myBox" /> the control's ViewState stays always empty, so it loses its properties if it's not always displayed. But if I...
1
by: M | last post by:
Hi everybody, I have a Web form with something like: <form id="Form1" method="post" onsubmit="javascript:submitForm();" runat="server"> I need the JavaScript function submitForm() to execute...
2
by: sunilthk | last post by:
Hi All, I have a question. If javascript is disabled how asp.net determines which control has caused the post back. As we know that when we clicks on the button the buttons name goes with posted...
25
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- ...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
5
by: ThomasJ | last post by:
Ok so I have a DataGrid of which I have added checkboxes for every row, and a delete button. All of the code for checking and actually deleting the rows runs fine, however, the javascript I have...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.