Main Page | Report Page

 

  .NET DotNet Forum Index » ASP.NET Forum » Call Javascript confirm from code behind...

Author Message
tshad...
Posted: Mon May 04, 2009 5:56 pm
 
In 3.5 is there a way to call a javascript confirm box from the code - not a
button - and get the response back before continuing on?

In my program, I want to be able to check the database to see if a company
exists after the save button is pressed and if it does not, then popup a box
asking if the user really wants to add this new company or not.

If so, continue with the save, if not stop the processing.

Thanks,

Tom
 
William Niver...
Posted: Mon May 04, 2009 6:53 pm
 
Howdy Tom!
I haven't created all the code for you, just the concept of how to create
the cycle of JavaScript calls CodeBehind and CodeBehind calls JavaScript
Back.

Hope it helps!

William

Default.aspx:

Code View:

<% at (no spam) Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<a href="javascript:LinkButton1.click();">Click to Cause Postback</a>
<div style="display: none;">
<asp:UpdatePanel ID="upnl_Main" runat="server"
ChildrenAsTriggers="false" UpdateMode="conditional">
<ContentTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text="" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>


Code Behind:

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles LinkButton1.Click
'Do your lookups, checking and validation here.
Dim ScriptBuilder As New StringBuilder
'Build custom Javascript depending on your results.
ScriptBuilder.Append("function MyScript() {" + Environment.NewLine)
ScriptBuilder.Append(" alert('Howdy, I am dynamically created
javascript.');" + Environment.NewLine)
ScriptBuilder.Append("}" + Environment.NewLine)
ScriptBuilder.Append("MyScript();" + Environment.NewLine)
'register the javascript to the update panel control and update that
panel.
ScriptManager.RegisterStartupScript(upnl_Main, upnl_Main.GetType(),
"MyScript", ScriptBuilder.ToString, True)
upnl_Main.Update()
End Sub

End Class

"tshad" <toms at (no spam) pdsa.com> wrote in message
news:uohbxPRzJHA.4800 at (no spam) TK2MSFTNGP06.phx.gbl...
Quote:
In 3.5 is there a way to call a javascript confirm box from the code - not
a
button - and get the response back before continuing on?

In my program, I want to be able to check the database to see if a company
exists after the save button is pressed and if it does not, then popup a
box
asking if the user really wants to add this new company or not.

If so, continue with the save, if not stop the processing.

Thanks,

Tom



 
Nanda Lella[MSFT]...
Posted: Tue May 05, 2009 2:26 pm
 
You can use a web service to acheive this. Call a webserver on button click
from javascript and return true or false based on your criteria..

--

Thank You,
Nanda Lella,
http://www.ctrlf5.net

This Posting is provided "AS IS" with no warranties, and confers no rights.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Wed Jul 27, 2016 10:16 am