|
Create a Event at run time in asp .net with out refresh a page
|
|
|
|
|
Incomplete/Unclear!
For now, based on what you asked, use AJAX to do your stuff with partial rendering of the page.
|
|
|
|
|
Hello Everyone
I have a scenario of restricting the user not to close the browser without logging out properly.If anyone have done this before please help me out with this.
Thanks in advance.
|
|
|
|
|
There is no defined/fixed way to completely handle the scenario. There are various ways one can exit an application without logging out.
On your side, do make sure session timeouts are set to logout users. Handle page unload event and try to send an AJAX request to server to logout - not a 100% accurate rate it will work.
|
|
|
|
|
|
Hello,
Think that your web site gets thousands of users, everyday, like social platforms. Which structure do you think answers your requests? Web security, speed etc.
MVC, Entity Framework, Asp.Net sqlconnections , Linq to SQL?
Thanks four your ideas,
Have a nice day.
|
|
|
|
|
MVC is cleaner than Web Forms, and with a social platform you'd be doing lots of AJAX, which you can do very well with MVC. So for your base framework, I'd go with MVC.
Your data layer is another story. You can achieve good performance with pretty much any data connection technique. However, as far as maintainability and good design, I'd go with LINQ to Entities.
alexalexalex1907 wrote: web site gets thousands of users, everyday
Facebook probably gets millions to billions of users every day. Thousands every second or minute. Just FYI.
As far as scaling goes, MVC on a cloud platform (e.g., Azure) should work very well. A database that can scale well is also a good idea (e.g., SQL Azure, which can do sharding).
|
|
|
|
|
|
|
Web Forms and EF works pretty well.
Really, just pick the one you either (a) have the time to learn because you don't know it/not used it yet or (b) use it because you're familiar with it and the manager says it's urgent. (It never really is).
There is an ongoing debate as to which is better; Web Forms or MVC. The real answer is neither - they both have good and bad points; you just have to decide which is best for you to use.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
I get the following error while trying to access an msacccess database ,i cant seem to figure it out,the error is
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Source Error:
Line 20: SQLString = "SELECT DISTINCT Position FROM applicant ORDER BY position"
Line 21: DBCommand = New OleDbCommand(SQLString, DBConnection)
Line 22: DBReader = DBCommand.ExecuteReader()
Line 23:
Line 24: While DBReader.Read()
the source code that generate d error is as follows
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Drawing" %>
<SCRIPT Runat="Server">
Sub Page_Load
Dim DBConnection As OleDbConnection
Dim DBCommand As OleDbCommand
Dim DBReader As OleDbDataReader
Dim SQLString As String
Dim Counter As Integer = 0
DBConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("miraflash.mdb"))
DBConnection.Open()
SQLString = "SELECT DISTINCT Position FROM applicant ORDER BY position"
DBCommand = New OleDbCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
Dim MyButton as New Button
MyButton.Text = DBReader("position")
MyButton.CommandName = DBReader("position")
MyButton.Width = Unit.Parse("100px")
MyButton.Font.Size = FontUnit.Parse("8pt")
AddHandler MyButton.Command, AddressOf Get_Books
ButtonArea.Controls.Add(MyButton)
Dim MyBlank As New Literal
MyBlank.Text = " "
ButtonArea.Controls.Add(MyBlank)
Counter += 1
If Counter Mod 3 = 0 Then
Dim MyBreak As New Literal
MyBreak.Text = "<br/>"
ButtonArea.Controls.Add(MyBreak)
End If
End While
DBReader.Close()
DBConnection.Close()
End Sub
Sub Get_Books (Src as Object, Args As CommandEventArgs)
Dim SQLString As String
SQLString = "SELECT ID, Surname, Firstname, middlename FROM applicant " & _
"WHERE position = '" & Args.CommandName & "' " & _
"ORDER BY ID"
BookSource.SelectCommand = SQLString
End Sub
</SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body><form Runat="Server">
<h3>Display Job Types</h3>
<asp:PlaceHolder id="ButtonArea" Runat="Server"/>
<asp:AccessDataSource id="BookSource" Runat="Server"
DataFile="miraflash.mdb"
SelectCommand="SELECT ID, surname, firstname, middlename, email,qualification FROM applicant
WHERE position = 'salesrepresentative' ORDER BY ID"/>
<br/><br/>
<asp:GridView id="BookGrid" DataSourceID="BookSource" Runat="Server"/>
</form>
</body>
</html>
can sombody help out with d solution
abiola
|
|
|
|
|
I read somewhere else that this error could be caused by using reserved words in your query. Try adding square brackets around your table and field names:
e.g. SELECT DISTINCT [Position] FROM [applicant] ORDER BY [position]
|
|
|
|
|
Hi,
I wanna have your opinion on these web stats, which one you'll recommend for advanced web stats:
1. Smarter Stats
2. AWstats
3. webalizer
|
|
|
|
|
Smart stats is new to me.
Webalizer I think is just terrible. I can provide more details.
AWStats is what I reach for again and again and again on a Windows or Linux web server.
There have been joys too great to be described in words, and there have been griefs upon which I have not dared to dwell, and with these in mind I say, climb if you will, but remember that courage and strength are naught without prudence, and that a momentary negligence may destroy the happiness of a lifetime. Do nothing in haste, look well to each step, and from the beginning think what may be the end. - Edward Whymper
Climb On!
|
|
|
|
|
hi all
i want use page mappageroutr in simple mvc project but i cant;
my code is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"viewstudent",
"view/viewstudent",
new { controller = "Movie", action = "Select", id = UrlParameter.Optional }
)
;
}
if i comment route "viewstudent" or comment route 'Default' my route is correct and work but two routmap with together dosent work!
thanks for any help
|
|
|
|
|
Hello.
Order of routes matters in MVC so in example above the default route will always hit for viewsudent. Swap them and it should work.
Take also a loot at this blog post[^] for debugging MVC routes.
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
thanks a alot
i swap two rout and it worked;
also thanks for this usefule link this blog post[^]
|
|
|
|
|
The "Default" route map should always be placed at the end. Try swapping the two MapRoute and it will work.
|
|
|
|
|
Hi,
I have a registration form which consists of, amongst others, an email field. When the user enters their email address, the onChange event is fired and a server side page method is called which checks the email address and returns a boolean value. This works fine when invoked from the onChange event of the textbox.
The problem occurs when the submit button is clicked; the submit button invokes the Javascript validation function and posts back if the form is valid, however, because the email validation involves an AJAX server side call, the function isn't waiting for the response and so causes the form to be submitted regardless of the email validation result. I hope I have explained this adequately but if not I have included a cut down version of my page:
<script type="text/javascript">
var pageIsValid;
var emailAddressMessage;
function ValidateForm() {
pageIsValid = true;
PageMethods.EmailAddressIsValid(document.getElementById('<%= txtNewMemberEmailAddress.ClientID %>').value, ValidateEmailAddressSuccess, ValidateEmailAddressFailed);
if (pageIsValid == false) {
alert('Some information is either missing or invalid. Hover your mouse over the red crosses for more information');
}
return pageIsValid;
}
function ValidateEmailAddressSuccess(result) {
if (result == false) {
document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";
emailAddressMessage = 'The email address you have entered is already in use';
pageIsValid = false;
}
else {
document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/tick.png";
emailAddressMessage = 'This field is valid';
}
}
function ValidateEmailAddressFailed(result) {
document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";
alert(result.get_message());
}
</script>
<asp:Button runat="server" ID="btnRegister" Text="Register" CssClass="button" OnClientClick='Javascript:return ValidateForm();' />
If anyone could suggest a better way of doing this it would be appreciated.
Thanks
Jay
|
|
|
|
|
You could try taking the "A" out of "AJAX".
Add the script below, and then change your PageMethods.EmailAddressIsValid call to SyncPageMethods.EmailAddressIsValid .
Type.registerNamespace("System.Net");
System.Net.XMLHttpSyncExecutor = function()
{
if (arguments.length !== 0) { throw Error.parameterCount(); }
System.Net.XMLHttpSyncExecutor.initializeBase(this);
};
System.Net.XMLHttpSyncExecutor.prototype =
{
executeRequest: function()
{
if (arguments.length !== 0) { throw Error.parameterCount(); }
var webRequest = this.get_webRequest();
if (this._started) { throw Error.invalidOperation(String.format(Sys.Res.cannotCallOnceStarted, "executeRequest")); }
if (null === webRequest) { throw Error.invalidOperation(Sys.Res.nullWebRequest); }
var body = webRequest.get_body();
var headers = webRequest.get_headers();
this._xmlHttpRequest = new XMLHttpRequest();
this._xmlHttpRequest.onreadystatechange = this._onReadyStateChange;
var verb = this._webRequest.get_httpVerb();
this._xmlHttpRequest.open(verb, this._webRequest.getResolvedUrl(), false);
if (headers)
{
for (var header in headers)
{
var val = headers[header];
if (typeof(val) !== "function")
{
this._xmlHttpRequest.setRequestHeader(header, val);
}
}
}
if ("post" === verb.toLowerCase())
{
if (null === headers || !headers["Content-Type"])
{
this._xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
}
if (!body)
{
body = "";
}
}
this._xmlHttpRequest.send(body);
if (null !== this._xmlHttpRequest)
{
this._responseAvailable = true;
webRequest.completed(Sys.EventArgs.Empty);
this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
this._xmlHttpRequest = null;
}
}
};
System.Net.XMLHttpSyncExecutor.registerClass("System.Net.XMLHttpSyncExecutor", Sys.Net.XMLHttpExecutor);
System.Net.WebServiceSyncProxy = function()
{
if (arguments.length !== 0) { throw Error.parameterCount(); }
System.Net.WebServiceSyncProxy.initializeBase(this);
};
System.Net.WebServiceSyncProxy.prototype =
{
_invokeSync: function(servicePath, methodName, useGet, params)
{
var e = Function._validateParams(arguments, [
{name: "servicePath", type: String},
{name: "methodName", type: String},
{name: "useGet", type: Boolean, optional: true},
{name: "params", mayBeNull: true, optional: true}
]);
if (e) { throw e; }
return System.Net.WebServiceSyncProxy.invokeSync(servicePath, methodName, useGet, params);
}
};
System.Net.WebServiceSyncProxy.invokeSync = function(servicePath, methodName, useGet, params)
{
var e = Function._validateParams(arguments, [
{name: "servicePath", type: String},
{name: "methodName", type: String},
{name: "useGet", type: Boolean, optional: true},
{name: "params", mayBeNull: true, optional: true}
]);
if (e) { throw e; }
var request = new Sys.Net.WebRequest();
request.set_executor(new System.Net.XMLHttpSyncExecutor());
request.get_headers()["Content-Type"] = "application/json; charset=utf-8";
if (!params) { params = {}; }
var urlParams = params;
if (!useGet || !urlParams) { urlParams = {}; }
request.set_url(Sys.Net.WebRequest._createUrl(servicePath + "/" + encodeURIComponent(methodName), urlParams));
var body = null;
if (!useGet)
{
body = Sys.Serialization.JavaScriptSerializer.serialize(params);
if (body === "{}") { body = ""; }
}
request.set_body(body);
var result = null;
request.add_completed(onComplete);
request.invoke();
function onComplete(response, eventArgs)
{
if (response.get_responseAvailable())
{
var statusCode = response.get_statusCode();
try
{
var contentType = response.getResponseHeader("Content-Type");
if (contentType.startsWith("application/json"))
{
result = response.get_object();
}
else if (contentType.startsWith("text/xml"))
{
result = response.get_xml();
}
else
{
result = response.get_responseData();
}
}
catch (ex)
{
}
var error = response.getResponseHeader("jsonerror");
var errorObj = (error === "true");
if (errorObj)
{
if (result)
{
result = new Sys.Net.WebServiceError(false, result.Message, result.StackTrace, result.ExceptionType);
}
}
else if (contentType.startsWith("application/json"))
{
if (!result || typeof(result.d) === "undefined")
{
throw Sys.Net.WebServiceProxy._createFailedError(methodName,
String.format(Sys.Res.webServiceInvalidJsonWrapper, methodName));
}
result = result.d;
}
if (statusCode < 200 || statusCode >= 300 || errorObj)
{
var err;
if (result && errorObj)
{
err = result.get_exceptionType() + "-- " + result.get_message();
}
else
{
err = response.get_responseData();
}
throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceFailed, methodName, err));
}
}
else
{
var msg;
if (response.get_timedOut())
{
msg = String.format(Sys.Res.webServiceTimedOut, methodName);
}
else
{
msg = String.format(Sys.Res.webServiceFailedNoMsg, methodName);
}
throw Sys.Net.WebServiceProxy._createFailedError(methodName, msg);
}
}
return result;
};
System.Net.WebServiceSyncProxy.generateSyncProxy = function(proxy, proxyName, syncProxyName)
{
var e = Function._validateParams(arguments, [
{name: "proxy"},
{name: "proxyName", type: String},
{name: "syncProxyName", type: String, optional: true}
]);
if (e) { throw e; }
if (proxy && proxy.prototype)
{
if (!syncProxyName || 0 === syncProxyName.length)
{
syncProxyName = proxyName + "Sync";
}
var item;
var foundMethods = [];
for (var key in proxy.prototype)
{
if ("string" === typeof(key) && "_" !== key.charAt(0) && "constructor" !== key && !key.startsWith("get_") && !key.startsWith("set_"))
{
item = proxy.prototype[key];
if ("function" === typeof(item) && 3 <= item.length)
{
item = item.toString();
item = item.replace(/function[^\(]*\(/g, "function(");
item = item.replace(/\(succeededCallback,\s*failedCallback,\s*userContext\)/g, "()");
item = item.replace(/,\s*succeededCallback,\s*failedCallback,\s*userContext\)/g, ")");
item = item.replace("this._invoke(this._get_path(),", "System.Net.WebServiceSyncProxy.invokeSync(" + proxyName + ".get_path(),");
foundMethods.push(syncProxyName + "." + key + "=" + item);
}
}
}
if (0 !== foundMethods.length)
{
eval(syncProxyName + "=function(){if(arguments.length!==0){throw Error.parameterCount();}throw Error.notImplemented();};");
for (var i = 0; i < foundMethods.length; i++)
{
eval(foundMethods[i]);
}
}
}
};
System.Net.WebServiceSyncProxy.registerClass("System.Net.WebServiceSyncProxy", Sys.Net.WebServiceProxy);
Sys.Application.add_init(function()
{
if (window.PageMethods)
{
System.Net.WebServiceSyncProxy.generateSyncProxy(window.PageMethods, "PageMethods", "SyncPageMethods");
}
});
function ValidateForm() {
pageIsValid = true;
if (!SyncPageMethods.EmailAddressIsValid(document.getElementById('<%= txtNewMemberEmailAddress.ClientID %>').value))
{
document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";
emailAddressMessage = 'The email address you have entered is already in use';
pageIsValid = false;
}
else
{
document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/tick.png";
emailAddressMessage = 'This field is valid';
}
...
return pageIsValid;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
WOW! You've either put a lot of thought into this answer or you've tackled this problem before! Either way thanks for the response, I will try this later today and let you know how it goes.
Thanks again
Jay
|
|
|
|
|
That looks like it will only work with .Net on the client side (i.e. on Windows), and probably only in IE.
Edit: also, synchronous HTTP requests lock the browser process (i.e. at least the page you're looking at) until it returns, which can potentially be the TCP timeout time. They're a pretty bad idea.
|
|
|
|
|
BobJanova wrote: That looks like it will only work with .Net on the client side (i.e. on Windows), and probably only in IE.
Nope. It works in Firefox, Chrome and Opera here. It's using the built-in XmlHttp object, which was added to all browsers several years ago.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You need to add an extra step to your submission process, if you want AJAX validation before submitting. At the moment your workflow looks like
Press button -> client validation -> post to server
... as a synchronous process. You need to do
Press button -> client validation -> send AJAX validation request (...) receive AJAX response -> post to server
The (...) is an asynchronous wait with an event handler set. As for all AJAX queries you need to handle long delays and dropped connections gracefully.
Do you actually need this? I would think that people would expect a 'Submit' button to submit a postback, and for it to return them to the form after a postback with server-side validation errors would be acceptable. You will always have to do the server side validation anyway, so this is purely a user convenience feature.
|
|
|
|
|
You're right actually, I probably don't need this feature. I have implemented server side validation which will ensure that invalid data doesn't get saved, so I suppose the post back is only a minor inconvenience to the user. There will still be the inline validation so the likelihood is that the user will correct their errors before submitting anyway (or maybe not!).
Thanks a lot
Jay
|
|
|
|
|