|
I am having an issue with canceling an event I added to the window's onBeforeUnload event, when the browser is IE (7,8, &9). In FireFox my RegisterOnSubmitStatement is sufficient to set a flag to skip the warning, but in IE that code gets called after the onBeforeUnload.
Here is the code in question:
ScriptManager.RegisterStartupScript(page, typeof(Functions), "NavigateAway", @"
window.SuppressExitWarning = false;
window.onbeforeunload = confirmExit;
function confirmExit(evt) {
var message = '" + JsEscape(message) + @"';
if (window.SuppressExitWarning == true) return;
if (typeof evt == 'undefined') evt = window.event;
if (evt) evt.returnValue = message;
return message;
};", true);
ScriptManager.RegisterOnSubmitStatement(page, typeof(Functions), "AllowNavigateAway", @"
window.SuppressExitWarning = true;
");
If you add an alert to the "AllowNavigateAway" script, you can see the behaviour in IE -> The onBeforeUnload message pops up, then the alert.
I have tried several ways to solve it, but they all have a flaw of some sort.
A) Adding a setting of the global variable on the OnClientClick event to all possible form submitters will invariably miss something. That is to say, I do not have any idea of what controls will be on the page and even if I iterate through the control tree, I am likely to miss something that it not usually a control that submits but has it's AutoPostBack set to true. (e.g. DropDownList)
B) Using jQuery to attach a method to the submit of the form is not an option because CKEditor has locked it up.
C) Tracking the postback through a hidden input fails because it is not updated until after the onBeforeUnload.
Any thoughts or ideas would be greatly appreciated.
|
|
|
|
|
Hello,
We have a web page which requires user to answer questions in form of dropdown list. these answers are written to database. ASP.NEt with SQL server. There is some javascript validation to make sure the user selects a value from the dropdown list.
When it is the above browser, the answers are not being captured. I have added some logging to this web page. since this is working in case of IE browsers. Listed below is the debugging statement.
Browser Type : Desktop
Browser Name : AppleMAC-Safari
Browser Version : 5.0
Browser Major Version = 5
Browser Minor Version = 0
Browser Platform = WinNT
Browser Supports Frames : True
Browser Supports Javascript : 1.4
Any thoughs/ ideas is much appreciated.
|
|
|
|
|
You may have a javascript error when posting back the form to the web server, that is interfering with the set value of the listbox.
You have to remark out the Javascript file, and test the form postback to the server to make sure it works, and then add the Javascript back in 1 object at a time until the whole form works.
If your using the Validator, which is javascript, then that may be returning a "return false", which cancels the form postback to the server.
At the end of validation, you need to return true, to post the form for a round trip to the server.
|
|
|
|
|
I'm using VB.NET and ASP.NET in VS2005 to create a web application that has some very similar code in five different webpages. This code enables/disables various controls depending on the actions allowed in the current page. I would like to consolidate this code into a subroutine in a class.vb file and call it from the aspx.vb files.
I’m using a Master Page with four contentpageholders. Only one has the controls in question, but herein lies my problem. I can access the controls on webpages not using the Master Page, but can’t make the code work with the contentpageholder.
Here is the code in the class file:
Public Sub SetControls(ByVal Controltype As String, ByVal StartCtrl As Integer, ByVal StopCtrl As Integer, ByVal SetValue As Boolean)
Dim myPage As Page
Dim intIndex As Integer
Dim objPlaceHolder As ContentPlaceHolder
myPage = TryCast(HttpContext.Current.Handler, Page)
objPlaceHolder = TryCast(myPage.FindControl ("rightcolumn"), ContentPlaceHolder)
**** If Not objPlaceHolder Is Nothing Then **** “Nothing”
Select Case Controltype
Case "TextBox"
Dim txtTextBox As TextBox
For intIndex = StartCtrl To StopCtrl
txtTextBox = TryCast (myPage.FindControl("TextBox" & intIndex), TextBox)
If Not txtTextBox Is Nothing Then
txtTextBox.ReadOnly = SetValue
Else
Exit For
End If
Next
End Select
End If
End Sub
End Class
And I call the procedure like this:
Sub LockControls()
Dim objMiscUtilities As New MiscUtilities
objMiscUtilities.SetControls("TextBox", 2, 20, False)
End Sub
Whenever I test the program the “objPlaceHolder” is always nothing, so the rest of the code is bypassed.
Any help will be greatly appreciated.
Ron Brewer
|
|
|
|
|
Hi,
I have a question here,
TryCast(myPage.FindControl ("rightcolumn"), ContentPlaceHolder)
In this sentence is 'rightcolumn' your contentplaceholder id in your page?
To access any control in your content form,use the below way.
Dim MyTxt As TextBox
MyTxt =CType(YOURContentPlaceHolderID.FindControl("YOURTextBoxID"), TextBox)
Hope this helps.
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
I tried your example and got a "rightcolumn not declared" error. If this is not what you meant tell me what I should use instead of the id of the contentplace holder and I will try that.
I've seen some posts on the web indicating that I should be using "Master.FindControl" to get to the contentplaceholder where the controls are, but then I get a "Master not declared" error. That code works in the aspx.vb page, but not in the class.vb.
I'm sure this has been attempted before, but so far my web surfing hasn't turned up any examples. It seems using a master page with contentplaceholders severely limits what you can do in a class file.
Anyway, thank you for your interest and input.
Ron Brewer
|
|
|
|
|
|
This problem has been resolved (with a lot of help from my friends) and I thought it would be worth while to post the solution to help any others who might be interested. It only took two relatively minor changes to make the code work. Here they are:
Original Procedure declaration
Public Sub SetControls(ByVal Controltype As String, ByVal StartCtrl As Integer, ByVal StopCtrl As Integer, ByVal SetValue As Boolean)
Original call to procedure
objMiscUtilities.SetControls("TextBox", 2, 20, False)
Corrected Procedure declaration
Public Sub SetControls(ByVal Controltype As String, ByVal StartCtrl As Integer, ByVal StopCtrl As Integer, ByVal SetValue As Boolean, ByVal objPlaceHolder As ContentPlaceHolder)
Corrected call to procedure
objMiscUtilities.SetControls("TextBox", 2, 20, False, Master.FindControl("rightcolumn"))
Ron Brewer
|
|
|
|
|
Great job!!
-Manognya
__________________________________________________
$ God gives what is best.Not what all you wish
|
|
|
|
|
Hi,
I'll make it short and clear (I hope).
We have two teams developping our product, the R&D and the 'Integrators'.
I'm not sure how the Integrators are called in english, maybe TPAM (Third Party Application Maintenance), anyway, let's say that Integrators = People working on the base product, adding or changing functionalities for a specific customer. And the R&D team beeing in charge of doing what's common to all of them (the customers).
The R&D team is in charge of developping functionalities available to all our customers, and the other team only does specific developments for specific customers.
The problem we're dealing with is that both teams may develop on the same web pages, controls, business logic etc. What happens is that our Release Manager deploys what the R&D team has been doing in some sort of common workspace, and he can't be aware of what's from one team or another, so a lot of times, the Integrators work is lost and our release manager spends hours finding the 'lost changesets' and re applying those modifications.
We're need to solve this problem and what we came with far now is to develop some sort of API exposing all the common asp.net events (page_init, load, render, etc.), we also should fire events when entering/exiting BL and DAL functions allowing the Integrators to develop 'manually', maybe injecting some asp.net code into the existing pages, also some code behind, javascript, etc. I'm not really sure if this is a reasonable idea or not, we've just been thinking for like 10 minutes and I wondered what did you recon in this kind of situations.
This is just an idea, because they may develop everywhere... Web, BL, DAL and Database (we have a project for that).
Just to be clear, we're developing a product, I'm not sure how it's technically called in English but our application will keep growing over time so we really need to do this right otherwise it will cost us a lot of time and money to correct that later when we'll have people using our 'API' (I'm calling this an API but I may be wrong about that)
Anyway, we're stuck here, I hope I was clear enough, if not tell me and I'll try again!
Thanks in advance
PD: I posted this in the ASP.NET and Design and Architecture forums, I apologize if this is not ok and you're free to delete one of them.
|
|
|
|
|
Hello,
I am new to implementing HTTPS. My site has all capabilities for https and the server is ready with the certificate. Now, i want to implement a functionality like we see in normal websites with https.
Like in gmail, if we try to change https in the addressbar tp http it will come back to https. The user cannot change it to http.
Any suggestion how to do it.
Please note that I have only one page to be in https and rest all are in http. I am doing in MVC 3.
Thanks,
modified 23-Jan-12 10:28am.
|
|
|
|
|
Something like below
Context.Response.Redirect(Context.Request.Url.ToString().Replace("http://", "https://"))
and vice versus in the Page.OnPreRender Page Cycle
|
|
|
|
|
Getting 404 file not found error while viewing the report after uploading project to the server using asp.net and ajax.
|
|
|
|
|
|
I've already read some articles about this matter, but I'm not sure how to solve my problem.
I work on project in which we use MVC3. The project should manage school system (schools, pupils, teachers, parents, users, roles and so on. In the center of such a school management system is - schedule of subjects.
We get data from MS SQL Server through EF4 (database first approach), which means all entity classes are created automatically. Therefore, I have such a classes that represent database tables such as School, Pupil, Teacher, Role and so on. And I have DbContext derived class.
We primarily know how our presentation (UI) layer should look like.
The problem is in layer between UI and classes we got automatically by using EF4 that I've already mentioned. I've read about repository and unit of work patterns and understood how they work. I've thought we could apply those patterns, but our project architect wants to use something else. He wants to have clear separation of layers. He wants to call simple methods from controllers that are placed in business layer, which means almost whole logic should not be in controllers, but in that business layer.
I'm not sure now what I should start with. I have all those entity classes School, Pupil, Teacher, Role and so on. And I have DbContext derived class. That means those classes are input for business layer. What should be output of business layer? How could I design business layer?
Thank you in advance.
Goran
|
|
|
|
|
I would suggest to keep your entity classes (generated from EF4) into database layer (separate C# class library). Don't keep them in models folder.
Your business layer methods should call them.
Your controller can call these business layer methods.
To use Entity class in your web project, add reference of your database layer.
This kind of architecture will give you a lot of flexibility in future.
|
|
|
|
|
Hello,
I am able to install multiple sites in http on the same server (using the http header).
unfortunatly i can't install it in https, I installed the certificate on port 443 for the first site then what must be done to the second site? Port 443 is used by the first site, Thanks for your help.
NB: I use IIS v6.0
|
|
|
|
|
guys, i have a problem that doesn't seem logical.
i have added this code to the Render() method of my new web control:
System.Web.UI.HtmlControls.HtmlGenericControl PreviewFrame = null;
if (!string.IsNullOrEmpty(this.PreviewFrameID))
{
PreviewFrame =(System.Web.UI.HtmlControls.HtmlGenericControl) this.NamingContainer.FindControl(this.PreviewFrameID);
if (btnSubmit == null) throw new HttpException("PreviewFrameID must point to an existing control on the page.");
PreviewFrame.Attributes.Add("name", PreviewFrame.UniqueID);
}
this code should add a name attribute to the Preview Frame to which i can target a response with type "image/jpeg".
<iframe id="PreviewFrame" runat="server"></iframe>
but amazingly, this doesn't work!!
Help people,so poeple can help you.
|
|
|
|
|
Ali Al Omairi(Abu AlHassan) wrote: target a response with type "image/jpeg".
What do you mean by this? You don't need a name attribute to identify an element, use the id. Most browsers will render the name attribute from the id attribute.
No comment
|
|
|
|
|
Sir;
I don't need to identify the element, actually I am trying to assign its name as a target of a form which I can respond its submission with an image/jpeg response. look the code below:
first i do the submission:
var iframe = setting.previewFrame;
var form = document.createElement('form');
form.method = 'post';
form.action = settings.action;
form.target = iframe.name;
then I build the response:
Response.ContentType = "image/jpeg";
Response.BinaryWrite(GetFileBytes());
Response.End();
using the iframe id wont work on FF or IE which are most used.
Help people,so poeple can help you.
modified 22-Jan-12 10:58am.
|
|
|
|
|
Well, this happens because method Render() occurs after the control is loaded what we should do is to move this code the the method OnLoad() like the code below:
protected override void OnLoad(EventArgs e)
{
System.Web.UI.HtmlControls.HtmlGenericControl PreviewFrame = null;
if (!string.IsNullOrEmpty(this.PreviewFrameID))
{
PreviewFrame = (System.Web.UI.HtmlControls.HtmlGenericControl)this.NamingContainer.FindControl(this.PreviewFrameID);
if (PreviewFrame != null)
if (string.IsNullOrEmpty(PreviewFrame.Attributes["name"]))
PreviewFrame.Attributes.Add("name", PreviewFrame.UniqueID);
}
}
Help people,so poeple can help you.
|
|
|
|
|
I have an asp.net for which the user fills. When the user clicks the submit button, the form is validated and also the database is checked if the entry with same fields is made. If the entry is already present then I need to pop up a confirmation box to confirm from the user if he wants to update the existing record.
Please let me know how to get the confirmation box on server button click after some instructions are processed in the code-behind page.
|
|
|
|
|
|
On a page I have and dymanicly generated ajax controls.
On Page_init
I created all dymanic controls however on asp:Button click event I can't find any of those dynamycly generated controls (FindControls not working). Could you tell me why?
myLiteralControl = New LiteralControl(" What type of student are you? ")
pnlQuestionnaire.Controls.Add(myLiteralControl)
Dim ddlDemographicTypes As New DropDownList
ddlDemographicTypes.ID = "ddlDemographicTypes"
pnlQuestionnaire.Controls.Add(ddlDemographicTypes)
Dim rfvDemographicTypes As New RequiredFieldValidator
rfvDemographicTypes.ID = "rfvDemographicTypes"
rfvDemographicTypes.Text = "* Required field"
rfvDemographicTypes.ControlToValidate = "ddlDemographicTypes"
pnlQuestionnaire.Controls.Add(rfvDemographicTypes)
Dim DemographicTypesCascadingDropDown As New CascadingDropDown
With DemographicTypesCascadingDropDown
.ID = "DemographicTypesCascadingDropDown"
.TargetControlID = "ddlDemographicTypes"
.Category = "DemographicTypes"
.PromptText = "< Please select>"
.ServicePath = "Service.asmx"
.UseContextKey = True
.ServiceMethod = "GetDemographicTypes"
.ContextKey = strGroupID
End With
pnlQuestionnaire.Controls.Add(DemographicTypesCascadingDropDown)
myLiteralControl = New LiteralControl("" & " ")
pnlQuestionnaire.Controls.Add(myLiteralControl)
End If
|
|
|
|
|
Dear All,
Please go through with my code. I do not understand why this is not working.I have searched alot and make this code.When i am checking my asms file in browser data is reflecting correctly in XML but when i am running in ASPX page nothing is happening.There is no error also
************.aspx page
my code here
webservice
[WebMethod]
public List<string> getAdmissionNo(string prefixText)
{
SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.AppSettings["MyCon"].ToString());
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("select Convert(varchar,AdmissionNo) As AdmissionNo from OA_ADM_tblAdmission_AdmissionDetails where AdmissionNo like @Name+'%'", sqlConnection);
sqlCommand.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
DataTable dt = new DataTable();
sqlDataAdapter.Fill(dt);
List<string> AdmissionNos=new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
string s =Convert.ToString(dt.Rows[i]["AdmissionNo"].ToString());
AdmissionNos.Add(s);
}
return AdmissionNos;
}
And aspx
<asp:ScriptManager runat="server" ID="sm"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtAdmisssionNo" runat="server" MaxLength="15"></asp:TextBox>
<asp:AutoCompleteExtender ID="autoCompleteExtender" runat="server" TargetControlID="txtAdmisssionNo"
MinimumPrefixLength="1" ServiceMethod="getAdmissionNo" ServicePath="~/Service.asmx" >
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
correct records
121010001/002
121020001/003
121020002/002
121010002/001
111020002/001
111020001/003
111010001/001
but our Autocomplete result displays this format
60505000.5
40340000.333333336
60510001
121010002
111020002
37006667
111010001
it was wrong.i want 121010001/002 this format records help me.
|
|
|
|
|