|
I'm using a details view for the first time.
I have a data access layer in my program so I'd like to avoid using the SQLDataSource Object if I can.
I've been trying to do an insert with the details view.
On my details view I have OnItemInserting="DetailsViewSubmit_Insert"
in my code section I have a function:
protected void DetailsViewSubmit_Insert(Object sender, DetailsViewInsertEventArgs e)
From what I'm reading the information the user typed into the text boxes is supposed to be an an Idictionary object at "e.Values"
However when I check e.Values.count its always empty.
Has someone else come across this problem, or perhaps is there a better way to use the details view?
Here's the full details view.
<asp:DetailsView ID="DetailsViewSubmit" runat="server"
Height="50px" Width="125px"
DataKeyNames="FeedbackKey"
DefaultMode="Insert" AutoGenerateRows="False"
OnItemInserting="DetailsViewSubmit_Insert">
<Fields>
<asp:BoundField HeaderText="Subject" DataField="Subject">
<ControlStyle Width="600px" />
</asp:BoundField>
<asp:BoundField HeaderText="Body" DataField="Body">
<ControlStyle Height="250px" Width="600px" />
</asp:BoundField>
<asp:CommandField ShowCancelButton="False" ShowInsertButton="True"
InsertText="Submit" />
</Fields>
</asp:DetailsView>
protected void DetailsViewSubmit_Insert(Object sender, DetailsViewInsertEventArgs e)
{
Response.Write("DetailsViewSubmit called - count = " + e.Values.Count);
}
|
|
|
|
|
The e.Values is only specified when you use the DetailsView control with a datasource control, here you have a data access layer you then may consider using the ObjectDataSource with the control. If you don't specify any datasource control in the DataSourceId property of the DetailsView, you'll need to manually get values from the control and do the insert command. You can read more about how to use the ObjectDataSource and DetailsView control in MSDN.
|
|
|
|
|
thank you for your previous help from before
I've been using a detailsview, an object data sources, with a data access layer, and a stored procedure, and my back to a problem with E.values.
What i'm trying to do is, after I insert a new event, I want to get the the key of the newly inserted event and set that key as my current key for the details view.
I've been playing with the parameter output, I know that i'm setting EventsKey to the newly added record. I tried to catch it in "OnItemInserted" but when I output all the values from e.values, the new key isn't part of that list.
I don't know where the output parameter would be stored, or if there's a better way to get this new key value back to the business layer.
Drathmar
Here's my code:
**Object Data source**
<asp:ObjectDataSource
ID="ObjectDataSourceDetailsView"
runat="server"
TypeName="AspNet.StudentHealthRecords.HealthDbUtility"
SelectMethod="EventsGetByKey"
InsertMethod="EventsAdd"
UpdateMethod="EventsUpdate"
>
<SelectParameters>
<asp:Parameter Name="EventKey" Type="String" DefaultValue="-1" />
</SelectParameters>
<InsertParameters>
<asp:SessionParameter Name="UserKey" SessionField="UserKey" Type="string" />
<asp:Parameter Name="EventDate" Type="String" />
<asp:Parameter Name="EventKey" Type="string" Direction="Output" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="EventKey" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
**data access layer function**
public static Boolean EventsAdd(string UserKey, string EventTitle, string EventDescription,
DateTime EventDate, out string Eventkey)
{
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("EventsAdd", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserKey", SqlDbType.Int, 4));
cmd.Parameters["@UserKey"].Value = UserKey;
cmd.Parameters.Add(new SqlParameter("@EventTitle", SqlDbType.VarChar, 20));
cmd.Parameters["@EventTitle"].Value = EventTitle;
cmd.Parameters.Add(new SqlParameter("@EventDescription", SqlDbType.VarChar, 500));
cmd.Parameters["@EventDescription"].Value = EventDescription;
cmd.Parameters.Add(new SqlParameter("@EventDate", SqlDbType.DateTime, 8));
cmd.Parameters["@EventDate"].Value = EventDate.ToShortDateString();
cmd.Parameters.Add(new SqlParameter("@DtTm", SqlDbType.DateTime, 8));
cmd.Parameters["@DtTm"].Value = DateTime.Now.ToShortDateString();
try
{
con.Open();
Eventkey = cmd.ExecuteScalar().ToString();
return true;
}
catch (SqlException err)
{
// Replace the error with something less specific.
// You could also log the error now.
throw new ApplicationException("Data error.", err);
}
finally
{
con.Close();
}
return false;
}
**procedure**
CREATE PROCEDURE [dbo].[EventsAdd]
(
@EventTitle varchar(20),
@EventDescription varchar(500),
@EventDate DateTime,
@UserKey int,
@DtTm DateTime
)
AS
INSERT INTO dbo.Events
(EventTitle, EventDescription, EventDate, EventCategory, UserKey, DtTm)
VALUES (@EventTitle, @EventDescription, @EventDate, 0, @UserKey, @DtTm)
SELECT SCOPE_IDENTITY()
GO
** Page function**
protected void DetailsViewItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
for (int i = 0; i < e.Values.Count; i++)
{
Response.Write("item Interted values are - " + e.Values[i] + "<br>" );
}
}
|
|
|
|
|
I have a brain dead third party component that will only show images in it's predefined images folder or in a specific url. I want to define the images in the skin file as with any normal asp.net control, unfortunately it's converted all my urls to relative from the root of the web and not from the theme folder automatically as it normally would.
It does have an imagesfolder property I can set, but since the theme in use depends on the user's selection I don't want to have to programmatically set that, if there were some sort of predefined url to the active theme set by asp.net I could use that in the skin file for the ImagesFolder property and circumvent the problem.
-- modified at 16:35 Thursday 10th August, 2006
|
|
|
|
|
AFAIK, there's no way that you can get reference to the currently active theme and set in the skin file (while you can do in code). I may not understand all your context, but IMHO there are a couple of things you may check:
+ Do you use the root path reference ~ when you set the ImagesFolder property for the custom control?
+ Because you are creating the skin file for a specific theme, so I think you may probably know the theme name and you can hard code this name in the ImagesFolder property of the control in the skin file.
|
|
|
|
|
I´ve heard that its possible to run a web app without aspx files and just host the dlls on the web server. Anyhow, I haven´t managed to get this to work and haven´t found any info about how to do this.
Does anybody know how it´s done?
|
|
|
|
|
|
Premise: I'm new to Web Services.
I have an application that makes use of some assemblies, containing a class library.
I want to communicate with a server (through web services) which must use the data types contained in the same assemblies used by the application.
So I added a reference to those assemblies into the asp.net project and then added a web reference to the web service in the client application project.
I wrote some methods in the web service, they work (from the browser, at least), but Visual Studio generates a stub for the web service exposing different data types (same class names but different namespaces).
So, how can I share the same data types between the web service and the client, keeping them both in the client and in the server (I don't want to "move" the class library into the server because the web service is a secondary tool and the application must also work without it)?
I tried strong-naming but nothing changed.
Thanks for any help.
|
|
|
|
|
I'd try putting all shared classes in the class library and ensure that you reference the class library from both the server and client projects.
i.e. Client app has a web reference to your web service as well as a reference to the class library.
Then ensure that all references in the web service proxy class in the client project reference objects from the class library.
|
|
|
|
|
Naes wrote: I'd try putting all shared classes in the class library and ensure that you reference the class library from both the server and client projects.
i.e. Client app has a web reference to your web service as well as a reference to the class library.
Then ensure that all references in the web service proxy class in the client project reference objects from the class library.
It is already built that way.
Thank you, anyway.
|
|
|
|
|
IMO, if you want the client and service to use the same objects, you might want to edit the proxy as basically the proxy will contain the implementations for custom objects that are used in the web service. If they don't get generated, the client has no idea to create the objects to work with the service, the exception is you add reference to the shared assembly. However, the downside of editing the proxy is that when you update the service, and you'll need to refresh the proxy and this issue could lead to overwrite the current proxy code. So I think you may trade off in this case, or may think off another way to call the service for example sending SOAP messages ....
|
|
|
|
|
I have a page that will display one of three sections depending on the type of object being edited. I want to send only one of those sections to the user down the wire depending on which type of object it is as each one contains a *lot* of controls.
There are many controls that allow hiding or showing a section dynamically at the end users's browser but they all will still result in the unneeded content being sent every time to the browser.
I'm looking for something that I can still use the UI editor to create and then optionally send or not in the page load event. I know i could just dynamically add those controls at runtime that apply, but that's a bit more clumsy than what I'm looking for and it's a pretty complex layout with a lot of controls.
I've been through all the stock components and methods but I don't think what I'm looking for is there.
I know that I could do this in a convoluted way through master pages and content areas, but that is way overkill for this and will introduce a lot of complexity un-necessarily.
Any ideas would be appreciated.
|
|
|
|
|
Hmmm... would the MultiView work for what you want?
|
|
|
|
|
No because all the content is sent to the user and any of it can be shown at any time in the browser.
What I want is like a panel maybe but one that you can, at the server during runtime, not only hide, but not send at all to the browser.
|
|
|
|
|
I'm not sure that's true. I think with a MultiView control, only the active View is sent to the user. I just did the following code as a test and can verify only the active View was sent.
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
int index=0;
if (Request.QueryString["view"] != null)
index = int.Parse(Request.QueryString["view"]);
mv1.ActiveViewIndex = index;
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form runat="server">
<asp:MultiView id="mv1" runat="server">
<asp:View id="view0" runat="server">
This is view0.
<asp:TextBox id="txt0" runat="server" Text="View0" />
</asp:View>
<asp:View id="view1" runat="server">
This is view1.
<asp:TextBox id="txt1" runat="server" Text="View1" />
</asp:View>
<asp:View id="view2" runat="server">
This is view2.
<asp:TextBox id="txt2" runat="server" Text="View2" />
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
|
|
|
|
|
So when you specify view 0 for example and view the page source in the web browser you don't see the txt1 or txt2 textboxes? I thought they were sent, just hidden at the client end because in many examples they describe showing different views *at the browser* by responding to click events etc. Or did I misunderstand that and they mean *at the server* after a postback?
|
|
|
|
|
Hi John. Nope- the hidden views are not sent to the browser at all.
Jon's point too about using a panel with visible=false works the same way. If it isn't visible, it isn't sent to the browser.
The one thing that may be sent would be viewstate for the controls - I'm not sure if viewstate for a hidden View in a MultiView control is sent to the browser or not. But if you try the example I posted for you, you'll see the hidden view controls are not sent to the browser at all.
|
|
|
|
|
Thank you Mike I appreciate it, I was making a bad assumption based on a 3rd party component's behaviour and a misunderstanding of some of the docs I was reading on multiview. I should have just tried it right off the start.
Cheers!
-- modified at 16:53 Thursday 10th August, 2006
|
|
|
|
|
Perhaps I'm missing the underlying problem, but can't you just use an asp:Panel to wrap your sections and set Visible=false for the sections you don't want to display?
|
|
|
|
|
I'm trying to cut down on the size of the page sent to the user. Setting Visible=false still sends that panel section to the browser from the web server.
|
|
|
|
|
How are you setting it up?
This:
---------------------------------------
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="TestWebApp._Default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Panel ID="pnlVisible" runat="server">
<asp:TextBox id="Textbox1" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox2" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox3" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox4" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox5" Runat="server"></asp:TextBox>
</asp:Panel>
<asp:Panel ID="pnlNotVisible" Visible="False" runat="server">
<asp:TextBox id="Textbox6" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox7" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox8" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox9" Runat="server"></asp:TextBox>
<asp:TextBox id="Textbox10" Runat="server"></asp:TextBox>
</asp:Panel>
</form>
</body>
</HTML>
---------------------------------------
renders this for me (.NET 1.1):
---------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="Default.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE" value="dDwtMTc2NDM4OTkxODs7Pm7rGtXI0cEYJ6T19tObP543riiK" />
<div id="pnlVisible">
<input name="Textbox1" type="text" id="Textbox1" />
<input name="Textbox2" type="text" id="Textbox2" />
<input name="Textbox3" type="text" id="Textbox3" />
<input name="Textbox4" type="text" id="Textbox4" />
<input name="Textbox5" type="text" id="Textbox5" />
</div>
</form>
</body>
</HTML>
---------------------------------------
Jon Sagara
When I grow up, I'm changing my name to Joe Kickass!
My Site | My Blog | My Articles
|
|
|
|
|
Thanks Jon, I was going by what I saw with a 3rd party component. I appreciate you taking the time to check it out, I should have just tested it with the stock component to begin with.
Cheers!
|
|
|
|
|
Don't know what browsers you have to support but couldn't you use iframe and point it to aspx or ascx as necessary?
only two letters away from being an asset
|
|
|
|
|
No it's not practical to do that, it's a very complex form with a very complex business object as the source of what's being edited on the form, to break it out into different pages would be a nightmare. There are about 20 controls in each of the three sections for a total of 60-ish and only 20 need to be displayed at a time. (I'm porting from a winform app)
|
|
|
|
|
Does anyone know how to get the date to 2 characters ie 2006 would be 06. this has been baffling me for a while now. Any help is much appreciated
|
|
|
|