Showing posts with label click. Show all posts
Showing posts with label click. Show all posts

Saturday, March 31, 2012

Server Side Code dependent on JavaScript

Is there a way I can launch a Server Side function from JavaScript?

On a Button Click, I am using JavaScript to print to current page. When the print has been sent, I want to run a Server Side Function to update a record (which also changes the screen so I have to wait until it prints to run the server side function).

Thanks.I imagine in your JS function, you could print and then do a postback to the server?
This may get your problem resolved.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Button1.Attributes.Add("onClick","javascript:DoSomething();");
string html = "";
html += "<script>";
html += " function DoSomething()";
html += " {";
html += " window.print();";
html += " }";
html += "</script>";
Response.Write(html);
}

private void Button1_Click(object sender, System.EventArgs e)
{
Update();
}

public void Update()
{
Response.Write("Now going to update the record.");
}
How to force a postback using javascript:

http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

Server side Event handler for DIV click?

Is it possible with ASP.NET C# to establish a click event on a DIV element so that when the user clicks on the DIV it can postback to the server and initate a click event for that DIV element? I am currently wrapping my content with a <A runat=server> to achieve the onserverclick effetc.

In fact if i wanted to create a server side event hanler for dynamic content, how would one go about establishing this. I can see .NET makes heavy use of __doPostBack on the client side but i just dont see how it can initate an event handler on the server side.

Tx

Hi quantass0,

You can handle the click event on a DIV as the code following (div1 is the id of the DIV element)

public

partialclass_Default : System.Web.UI.Page,IPostBackEventHandler

{

protectedvoid Page_Load(object sender,EventArgs e)

{

div1.Attributes[

"onclick"] = ClientScript.GetPostBackEventReference(this,"ClickDiv");

}

protectedvoid Div1_Click()

{

// Do something

}

#region

IPostBackEventHandler Memberspublicvoid RaisePostBackEvent(string eventArgument)

{

if (!string.IsNullOrEmpty(eventArgument))

{

if (eventArgument =="ClickDiv")

{

Div1_Click();

}

}

}

#endregion

}

Hope this helps


Excellent info. Thank you!

Hi, i wonder if you could help me, i'm trying to get this work inside a user control. It doesnt implementSystem.Web.UI.Page,

i have tried the followng code but i cant pick up the event

Sorry, this is converted to vb as well

Code behind is

Imports System.ReflectionPartialClass editControllerBarInherits System.Web.UI.UserControlImplements IPostBackEventHandlerProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs EventArgs) cancelDiv.Attributes("onclick") =Me.Page.ClientScript.GetPostBackEventReference(Me,"ClickDiv")End Sub Protected Sub Div1_Click()' Do somethingEnd Sub Private MembersAs IPostBackEventHandlerPublic Sub RaisePostBackEvent1(ByVal eventArgumentAs String)Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEventIf Not String.IsNullOrEmpty(eventArgument)Then If eventArgument ="ClickDiv"Then Div1_Click()End If End If End Sub

the div on the user control looks like this

 <div class="btnCancel" runat="server" id="cancelDiv"> </div>
 
could you help please? 

Thursday, March 29, 2012

server side or client side page?

a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?
it seems to me that in asp.net everthing is server side, where are the client side pages?
thanks

The sp is server side, but the validation can be on or the other, depending on how it's coded.
ASP.Net has it's validations, so it's server side when using them.
But you can also make validations via JavaScript, so that would be client side.
Zath


but the validation controls (like RequiredFiledValidator) is a client side validation...,isnt that right?

because i know that if any of the validators are found to be on error the submission of the form to the server is cancelled...
so is there something that is done on the client side in asp.net?
thanks for the help


ppl1 wrote:

but the validation controls (like RequiredFiledValidator) is a client side validation...,isnt that right?

because i know that if any of the validators are found to be on error the submission of the form to the server is cancelled...


Yes the RequiredFieldValidator does the client side validation

ppl1 wrote:


so is there something that is done on the client side in asp.net?
thanks for the help


You can do so many things on client side and you should do so many things on client side to minimize postbacks if possible. So what exactly is that you are asking. Usually you use javascript to do client side stuff..


ok...so lets go back to my first question-> a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?

ppl1 wrote:

ok...so lets go back to my first question-> a page that contain a validation control and starting a storeProcedures when the user click on a button --is considered as a client side page or as a server side page?


A webpage physically is considered a client side output for the asp.net server side processing. Asp.net uses browser to show its output to the user in the form of a web page. So, a webpage is a client side entity. Server wouldnt know anything about it after it outputs the html into the browser. Now, when the user clicks on the button, the page gets postback to the server. In here there are several things that goes on. The event of user clicking the button will be a client side event, and the page postbacks and server does some processing in response to the user action, which is button click event.

ok thanks for the help
Hi ,
Answering your question, calling a Stored Procedure is a Server Side call.
A page can contain server as well as client side technologies.
Hope it helps
Shahram