|
If it works for all the built-in controls, but your custom control, then I also think it may be down to your code. If you don't mind and cannot find the root cause, can you post it here, I'll have a stab at it.
|
|
|
|
|
Sure, no problem.
I've cleared out some of the code that references my business logic class, since you dont have access to it. This includes a public property for assigning an instance of my BL-class to the control, and this property shows up in the properties window in design mode when this control is included in a web page.
This is the source for one of my ascx pages:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EducationEdit.ascx.cs" Inherits="cv_EducationEdit" %>
<table width="600">
<tr>
<td align="right">
<asp:LinkButton ID="btnAddEducation" runat="server" Text="[Lägg till utbildning och kurser]" OnClick="btnAddEducation_Click"/>
</td>
</tr>
</table>
<asp:Panel ID="pnlEditEducation" runat="server" Visible="false">
<table width="600">
<tr>
<td>Typ</td><td><asp:DropDownList ID="ddlType" runat="server"/></td>
</tr>
<tr>
<td>Utbildning</td><td><asp:DropDownList ID="ddlName" runat="server"/></td><td><asp:TextBox ID="txtName" runat="server"/><asp:Button ID="btnNewName" runat="server" Text="Ny" OnClick="btnNewName_Click" CssClass="stdButton"/></td>
</tr>
<tr>
<td>Institut</td><td><asp:DropDownList ID="ddlEducator" runat="server"/></td><td><asp:TextBox ID="txtEducator" runat="server"/><asp:Button ID="btnNewPlace" runat="server" Text="Ny" OnClick="btnNewEducator_Click" /></td>
</tr>
<tr>
<td>Datum</td><td><asp:DropDownList ID="ddlStartYear" runat="server"/>-<asp:DropDownList ID="ddlStartMonth" runat="server"/> - <asp:DropDownList ID="ddlEndYear" runat="server"/>-<asp:DropDownList ID="ddlEndMonth" runat="server"/></td>
</tr>
<tr>
<td>Visa vid export</td><td>
<asp:CheckBox ID="ShowInFile" runat="server" /></td>
</tr>
<tr>
<td><asp:Button ID="btnSave" runat="server" Text="Spara" OnClick="btnSave_Click" CssClass="stdButton"/><asp:Button ID="btnCancel" runat="server" Text="Avbryt" OnClick="btnCancel_Click" CssClass="stdButton"/></td>
</tr>
</table>
</asp:Panel>
And this is the corresponding code-behind (.cs):
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class cv_EducationEdit : System.Web.UI.UserControl {
public delegate void UpdateEventHandler();
public event UpdateEventHandler Update;
private const string PAGESESSION_EDUCATION = "pEducation";
/// <summary>
/// Fills the drop downs
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
pFillEditValues();
}
}
/// <summary>
/// Fires an update event to inform the parent control that the current item has been saved and updated.
/// Used for informing the parent control to update all lists with Technical Skills
/// </summary>
protected virtual void OnUpdate() {
if (Update != null) {
// Invokes the delegates.
Update();
}
}
/// <summary>
/// Fills the drop downs and text boxes with possible values
/// </summary>
private void pFillEditValues() {
//Code to fill drop down combos
}
/// <summary>
/// Adds a new name of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewName_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtName.Text, txtName.Text);
ddlName.Items.Add(li);
ddlName.SelectedIndex = -1;
li.Selected = true;
txtName.Text = "";
}
/// <summary>
/// Adds a new educator of educations to select from
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNewEducator_Click(object sender, EventArgs e) {
ListItem li = new ListItem(txtEducator.Text, txtEducator.Text);
ddlEducator.Items.Add(li);
ddlEducator.SelectedIndex = -1;
li.Selected = true;
txtEducator.Text = "";
}
/// <summary>
/// Hides the new button and opens the control in edit mode with a new blank item
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAddEducation_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = true;
btnAddEducation.Visible = false;
}
/// <summary>
/// Saves the current item, hides the edit panel, shows the add button and fires an Update event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e) {
//Create or update my custom object
txtName.Text = "";
txtEducator.Text = "";
//Trigger event
OnUpdate();
pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
/// <summary>
/// Hides the edit panel and displays the add button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e) {
pnlEditEducation.Visible = false;
btnAddEducation.Visible = true;
}
}
And this is the code I use for including the control in a web page(aspx):
<div class="cvParagraph">
<uc4:EducationEdit ID="EducationEdit1" runat="server" OnUpdate="EducationEdit_Update" />
</div>
Thank you for taking your time with me!
Carolina Berglund
Consultant, systemdeveloper and architect.
|
|
|
|
|
Hi there,
Ahh web user control, historically VS 2003 does not support displaying the custom properties/events of a web user control .ascx in Properties windows and Intellisense is not provided in the Html view (now is the Source View in VS 2005). And when the VS 2005 comes out, there are a couple of improvoments like displaying the custom preperties in the Properties windows, and the Intellisens is also supported in the Html view. However, it still does not support adding the event handler for a web user control from the Properties windows. That being said, your choices are to add the handler in the Source view then manually add the source for the handler or you can add in code behind for example in the InitializeComponent method and have VS 2005 generate the method implementation.
|
|
|
|
|
|
hi!, there is a page, say, my.aspx. in this there is a .... block contains a function say func(). i want whenever my.aspx page loaded this function func() get executed on every post back.
|
|
|
|
|
You can call that javascript function on onload event of the body tag in the html section.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks! but i have to passed some values from code behind from to that java script function.
|
|
|
|
|
Hi,
u can use the following server side function.
if (!(this.IsStartupScriptRegistered("Startup")))
Page.RegisterStartupScript("StartUp","fun('"+ arg1 + "')");
|
|
|
|
|
exactly same way you can do as psamy said. also you can even write complete function in code behind itself.
Best Regards,
Apurva Kaushal
|
|
|
|
|
|
something like this you can use..:
string str = "<script language='javascript'>";<br />
str += "function Focu(){";<br />
str += "document.getElementById('TextBox3').focus();}<";<br />
str += "/";<br />
str += "script>";<br />
if(!IsStartupScriptRegistered("Test"))<br />
{<br />
Page.RegisterStartupScript("Test",str);<br />
}
Best Regards,
Apurva Kaushal
|
|
|
|
|
Thanks! It Working Correctly.
|
|
|
|
|
always welcome...
Best Regards,
Apurva Kaushal
|
|
|
|
|
There are several ways.
You could insert a value in the function:
var x = <asp:Literal id="objValue" runat="server" />;
and in the codebehind insert the value:
objValue.Text = "42";
You could make the body tag accessible from codebehind:
<body id="Body" runat="server">
and set the onload event from codebehind:
Body.Attributes["onload"] = "somefunc(42);";
You could add the code in a script tag:
this.ClientScript.RegisterStartupScript(this.GetType(), "init", "somefunc(42);", true);
Note that if you use RegisterStartupScript the code will run while the page is loading, not when it has finished loading, as it does when you use the onload event.
---
b { font-weight: normal; }
|
|
|
|
|
Ok, perhaps I just don't get it. I'm an old asp developer... I've been using .net 1.1 for some time now. Now I'm tasked with implementing a new asp.net 2 site on top of an older sql 2000 db.
This is where things get whacked for me: every article I can find wants me to use the aspnetdb (whether in sql Express or by porting it over to an existing sql database). But the database I have already contains the username and password stuff. DOes this mean I must re-write all of the logic to look this information up in other tables across databases? Does this mean I must re-code my object model?
Help me obi wan... isn't there a better way?
-- modified at 1:35 Wednesday 16th August, 2006
|
|
|
|
|
Hi there,
The ASP.NET 2.0 privides a couple of common services like Membership, Roles ... in the provider model using the predefined tables in the aspnetdb database (or you can install in your current db). And to use these services, you are only required to do some configurations without writing any line of code. However, if you want to use these services with your custom database schema then you need to privide your own custom providers[^]. In addition, you can keep using your custom object model to do all the common tasks instead of using the supported services.
|
|
|
|
|
Yes, I see regarding the membership, roles, etc... however it's tough to re-write your database when everything centers around it, you know? I did find out late last night that it seems to be the best route to write a custom provider. I can't believe how long it took me to find out this information... I would think this was a more common problem..? Oh well, thank you so much for replying.
|
|
|
|
|
Ok, so I've written the entire thing... it accesses my previously built database... if there is anyone out there who would like to see the process from beginning to end, let me know and I will post an easy to use article...
|
|
|
|
|
hello every one,
i want to know the way that How to register a javascript function against the server side button click in .cs file of ASP.net.
plz do tell me.
as function is
function fun()
{
alert("Error");
}
asp : input type=button runat=server onclick="javascript:func();"
Mairy
-- modified at 23:55 Tuesday 15th August, 2006
|
|
|
|
|
you can attach a javascript like this to a button in the code behind file:
btnID.Attributes.Add("onclick","javascript:fun();");
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi, I'm getting this error occassionally.
Exception Details: System.InvalidCastException: Unable to cast object of type 'ASP.main_master' to type 'ASP.main_master'.
I have to edit and resave main.master file for it to go away. but then i comes back? Anyone having same problem?
silverfox_1188
|
|
|
|
|
Are you doing anything complicated with your master file, like nesting and such? If not, start with disabling any virus scans that may be going through your project (and rest of your machine).
Also, I found an article that suggests to use the 'Register' directive to solve this issue...
http://www.pcreview.co.uk/forums/thread-2441960.php[^]
Nila
|
|
|
|
|
Hi, Thank You for your help.
I do not have nested master page. I only have one master page. However, in the master page, I have public properties and methods that can be accessed by pages using the master page. I never seen this error in development server, but one we launch this into production. We start seeing this error. We do have systemtec anti virus installed. I did disable the auto protection feature from scaning the \Temporary asp.net files\ folder in the Microsoft.Net 2.054 folder. But that doesn't seem to help. Do you think I should disable the scanner completely? Why would disabling help?
Also, I have a hunch that something is deleting the dynamically generated xxMain.Master.cs files in the temporary folder. It explains why editing and resaving the main.master file, the error goes away. Because in Asp.net 2.0, any change to the aspy and.cs files, those files will recompile and dynamically generated new .cs in the temporary folder. The problem is I don't know what is deleting it. could it be the virus scanner?
Thanks
Jim
silverfox_1188
|
|
|
|
|
AFAIK, Microsoft have confirmed that this is their product's issue[^] and it normally happens when you use some directives like MasterType, Reference, ... to create a strongly typed reference to the MasterPage, Web Page or User Control, so the best bet is to contact Microsoft support. However, there are a couple of options that you may try to work around this error:
+ Use the TypeName intead of the VirtualPath in the MasterType directive.
+ Define the properties/methods in a base class or an interface, and have the MasterPage inherit/implement this base class/interface. You can cast the MasterPage type to its parent type before calling its properties/methods.
+ Set the batch attribute in the compilation entry to false in the web.config file.
|
|
|
|
|
Hi Jim,
Do you have one of those 'sweeper' softwares installed on your prod server? Sounds like something is deleting your .net generated files (and you certainly do need them!!!). Try and see if there is a pattern associated with this issue... e.g. after every Wednesday morning, etc. If so, then it must be some software that intends to clear cache and temp files, and in the process it also clears out your .net generated files that happen to sit in a temp folder.
Also, check to see if you are running index server in your .net temp folder. Im sure you already know, but just to be sure this is the path:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
The disabling of virus scans and stopping the indexer is suggested by microsoft. I don't know if this is a bug or not, but it is a bad practice to disable virus scans just to make an app run.
I'll ask other developers here about your problem and see what's their two-cent on your issue
Nila
|
|
|
|