redho home | products | services
Web Design Forums

Web Design Forums  


Web Hosting, Web Design, Software and Web Development Forums  
 FAQFAQ   MemberlistArchive  Log inLog in   RegisterRegister 
         

How to call a ServerSide Script through Javascript



 
Post new topic   Reply to topic    Web Design Forums -> Web Development Discussion
View previous topic :: View next topic  
Author Message
Coddie



Joined: 22 Jul 2005
Posts: 11
I would like to know if there is a way by which I can Call a Serverside script through a Javascript. Or else is there a way to Postback a page through a javascript function.

Thanks in advance
  Reply with quote


Tom
Guest




I used a query string from Javascript ,something like

Code:
Var windid = window.open("default.aspx?frameheight="+mapframeheight+"&framewidth="+mapframewidth+"");


Which sends these values to the server.

Hope it helps.
  Reply with quote
Coddie



Joined: 22 Jul 2005
Posts: 11
Thanks for your quick response.

Yes, this sends information to the server and not the server side script. Actually your code will try to load a new page from the URL specified but does not post back the calling aspx page or invoke an event in the Server side script. This is what I need.

Let me explain you the need (May be this will help you understand the Problem better),

Say you have an E-Mail service like Yahoo and hotmail. When a user logs into his account I will make an entry in the database saying that "User X has logged in will Blah blah ...Time...” This can be done through the Page load event.

If another user tries to login to the same E-mail Account. I should be able to throw him out saying "Get out Mr.Y...”

The problem that I am currently facing is that... I am not able to keep track of the first user, i.e., if he is still using the window or not. This cannot be done through the server side script because we do not have a page_UnLoad event in Aspx.

Work Around:

I can keep a Log out hyperlink where I can check if the user has logged out or not. But the problem is what if the user closes the window abruptly with out using the Log out Hyperlink (you see there are few stinking users).

Our JavaScript will help us in this issue. It has a unload system function which when declared in the Body tag will be triggered when the page Closes. (This is simply fast)

But I am not able to send the information from the JavaScript to the database to remove the user’s record from the database. SO I have to call a server side event (or a postback to the calling page) to update the database. AND this is where I need your help.
  Reply with quote
Tom
Guest




Its good you said your purpose in detail,your first post lacked description.

I had to do something similar, a couple of months ago.But my luck I used a frameset.It was intended for a different purpose(The client wanted me to hide the URL) but it really helped for passing values from javascript to server side scripting.

I used something like this whenever I wanted to execute something on the server side from a javascript.
window.open(""default.aspx?f=1"" ,""mainframe"");

On the server side I checked for value of f and executed some database code.

Since the Javascript is client - side and VB.NET or C#.NET is Server side script, I dont think you can call server side codes from inside Javascript.

There is always a workaround.
Somebody here might help you on that.
  Reply with quote
Coddie



Joined: 22 Jul 2005
Posts: 11
Thanks a lot for your Help Man. That was indeed helpful. If you dont mind, can you explain what did you do with the frameset? So that I will try to tweak up the Code.
  Reply with quote
Tom
Guest




Frameset
With frameset, you can display more than one webform in the same browser window. Each frame is independent of the others.

Disadvantages:
1.Its a mess when you try tuning your frameset for different screen resolution.
2.Each browser has some compactibility issue,but I can be solved easily
3.The web developer must keep track of more webforms.
4.It is difficult to print the entire page.

Advantages:
1.Its really easy to use.
2.You can invoke a server script from a Javascript.

For my application I had three frames.
1.Logo
2.Left frame
3.Right frame

The Logo webform is my secret hide out.I have some hidden server side codes.

The left frame had various buttons like,
1.compose
2.edit profile
3.Signout
4.bla
5.bla bla

when the user clicks these buttons,for example edit profile
I'll executed the server script for calling the corresponding page (Editpage.aspx) on the right frame by something like this..

Dim strReDirectToAnotherFrame As String = "<script>window.open(""edit.aspx"" ,""rightframe"");</script>"
Response.Write(strReDirectToAnotherFrame)


POSSIBLE WORK AROUND FOR YOU IF YOU USE FRAMES
When the user closes the window,you can invoke a javascript function and send a query string to another frame,lets say Logo.aspx.

Javascript side on leftpage to send a javascript to server script.

//leftpage.aspx..This function must be invoked when the user close the window.

function clearflag()
{
window.open(""logo.aspx?flag=1"" ,""Logo"");
}


On the server script,

//logo.aspx

Dim flag as string
flag = Request.QueryString("flag")
If (flag = 1) then
//Connect to the database and update the table

End If

Hope this Helps.
  Reply with quote
Page 1 of 1
Post new topic   Reply to topic    Web Design Forums -> Web Development Discussion


Dubai Forums - Expat Help | Vegan Chat | Java Programming | Free 3D tutorials and 3d textures | Paris Forum | EU Forum
Free Dubai Classifieds | Free London Classifieds | Jobs in London

High Quality, Custom 3d animation and Web Design solutions Royal Quality Web Hosting Services Vegetarian and Animal Rights news

Powered by phpBB © 2001, 2005 phpBB Group