User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,753 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 21980 | Replies: 7 | Solved
Reply
Join Date: Jul 2005
Posts: 6
Reputation: naveenchander is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
naveenchander's Avatar
naveenchander naveenchander is offline Offline
Newbie Poster

Solution How to call a ServerSide Script through Javascript

  #1  
Jul 8th, 2005
Hi,

I am new to ASP.Net. 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

Thanks,
NaveenChander
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: How to call a ServerSide Script through Javascript

  #2  
Jul 8th, 2005
I used a query string from Javascript ,something like

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

Which sends these values to the server.

Hope it helps.
Save White Tiger
Reply With Quote  
Join Date: Jul 2005
Posts: 6
Reputation: naveenchander is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
naveenchander's Avatar
naveenchander naveenchander is offline Offline
Newbie Poster

Re: How to call a ServerSide Script through Javascript

  #3  
Jul 10th, 2005
Hi Mr White Tiger, :-)

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.

Hope it make sense.

I know this mail is toooo Long. Kindly bare ;-)

Thanks,
NaveenChander
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: How to call a ServerSide Script through Javascript

  #4  
Jul 10th, 2005
Yo FISH(I dont know the name of the fish but I remember seeing something similar in National Aquarium in Washington DC) ;-)

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.
Save White Tiger
Reply With Quote  
Join Date: Jul 2005
Posts: 6
Reputation: naveenchander is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
naveenchander's Avatar
naveenchander naveenchander is offline Offline
Newbie Poster

Re: How to call a ServerSide Script through Javascript

  #5  
Jul 11th, 2005
Hi Mr. White Tiger,

The Name of the fish is Dory a Cartoon character in the movie Finding NEMO.

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.

Thanks,
NaveenChnader
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: How to call a ServerSide Script through Javascript

  #6  
Jul 11th, 2005
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.



Originally Posted by naveenchander
Hi Mr. White Tiger,

The Name of the fish is Dory a Cartoon character in the movie Finding NEMO.

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.

Thanks,
NaveenChnader
Save White Tiger
Reply With Quote  
Join Date: Jul 2005
Posts: 6
Reputation: naveenchander is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
naveenchander's Avatar
naveenchander naveenchander is offline Offline
Newbie Poster

Re: How to call a ServerSide Script through Javascript

  #7  
Jul 12th, 2005
Yo Mr.Tiger,

Thanks a lot dude. That was indeed helpful. Frameset is very useful indeed.

Thanks again for all your patience and efforts.

Thanks,
NaveenChander
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: How to call a ServerSide Script through Javascript

  #8  
Jul 12th, 2005
No Problem
Save White Tiger
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 8:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC