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

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.

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

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.

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

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.

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

Edited 3 Years Ago by pyTony: fixed formating

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

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

use ClientScript.RegisterClientScriptBlock
to register ur scipt or u may do this as
use asp:button and on onclick event do ur coding then hide it by writing down this code on load page

btnname.style.add("display","none")

then do this by javascript
function calingbtnevent()
{
document.getElementByid(btnname).click(); //btname server button id
or 
u may do this as well
document.getElementByid('<%=btnname.ClientID%>').click(); 
}

use this function as ur requiremnt
Happy coding

Edited 6 Years Ago by __avd: For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

i wrote one script function in source code in asp.net with c# coding use this pages,how do i can access the function in code behind side (Ex .. cs page)?

ex : page.registerstartupscript()

pls help me

by chandran

Edited 5 Years Ago by __avd: Email snipped. Do not ask anyone (member or moderator) for help by email or PM

This question has already been answered. Start a new discussion instead.