Answered by:
I wish to place a Session variable in asp.net vb Insert

Question
-
User735297519 posted
I am using VWD 2008 express edition to edit the code below.
The HTML Insert Code is as follows: I have no code behind.
<Fields>
Line 24 <asp:TemplateField HeaderText="RecordID" SortExpression="RecordID">
Line 25 <InsertItemTemplate>
Line 26 <asp:TextBox ID="NewID" runat="server" Text='<%# Session["RecordID"] %>'></asp:TextBox>
Line 27 </InsertItemTemplate>
Line 28 <ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RecordID") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Font-Bold="False" />
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
I get the following compilation error
Line 24: <asp:TemplateField HeaderText="RecordID" SortExpression="RecordID">
Line 25: <InsertItemTemplate>
Line 26: <asp:TextBox ID="NewID" runat="server" Text='<%# Session["RecordID"] %>'></asp:TextBox>
Line 27: </InsertItemTemplate>
Line 28: <ItemTemplateWith the following Compilation Error Message
Compiler Error Message: BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Data.DataSetExtensions\3.5.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.WorkflowServices\3.5.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Runtime.Serialization\3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.IdentityModel\3.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml.Linq\3.5.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel.Web\3.5.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\dreamincode\32f9d892\2443638f\App_Web_hvm5zyle.dll" /D:DEBUG=1 /debug+ /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls /warnaserror- /optionInfer+ "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\dreamincode\32f9d892\2443638f\App_Web_hvm5zyle.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\dreamincode\32f9d892\2443638f\App_Web_hvm5zyle.1.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\dreamincode\32f9d892\2443638f\App_Web_hvm5zyle.2.vb"
Microsoft (R) Visual Basic Compiler version 9.0.30729.1
Copyright (c) Microsoft Corporation. All rights reserved.
C:\asp.net-files\Dreamincode\DetailPage.aspx(26) : error BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments.
dataBindingExpressionBuilderTarget.Text = System.Convert.ToString( Session["RecordID"] , System.Globalization.CultureInfo.CurrentCulture)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Detailed Compiler OutputC:\asp.net-files\Dreamincode\DetailPage.aspx(26) : error BC30203: Identifier expected.
dataBindingExpressionBuilderTarget.Text = System.Convert.ToString( Session["RecordID"] , System.Globalization.CultureInfo.CurrentCulture)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My objective is to populate the DetailsView with a single field in ASP.Net VB, when Inserted, a Record will be created with only a key field.Monday, August 8, 2011 1:58 PM
Answers
-
User-1694870838 posted
Hi,
Please refer to the code following:
public void @__DataBinding__control17(object sender, System.EventArgs e)
{
TextBox dataBindingExpressionBuilderTarget;
IDataItemContainer Container;
dataBindingExpressionBuilderTarget = ((TextBox)(sender));
Container = ((IDataItemContainer)(dataBindingExpressionBuilderTarget.BindingContainer));
if ((this.Page.GetDataItem() != null)) {
dataBindingExpressionBuilderTarget.Text = Convert.ToString(this.Eval("Name"), CultureInfo.CurrentCulture);
}
}
could you please give us your more code in the forum so that we can help you as soon as possible?
Best Regards,
Damon
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 11, 2011 11:57 PM -
User-1694870838 posted
Hi,
I'm sorry for reply later!
From your code, you have a error on Text='<%# Session["RecordrID"]%>', in the VB you can use it like <asp:TextBox ID="TextBox1" runat="server" Text='<%# Session("RecordrID")%>'></asp:TextBox>, it is a () not [].
Best Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2011 3:21 AM -
User-1694870838 posted
Hi Brown,
Do you mean that you want to insert Session[RecordID] value into DBase?
Please check your code :InsertCommand="INSERT INTO Members (RecordID) VALUES(@RecordID)". From your details, the @RecordID is Null, I think you can pass value like : <InsertParameters>
<asp:SessionParameter name="SessionID" SessionField="SessionID"/>
</InsertParameters>Best Regards,
Damon
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 19, 2011 1:19 AM -
User-1694870838 posted
Hi Brown ,
I'm sorry for my reply late, because of weekends.
From you details, you want to direct to another page after inserting data into DBase, you can add ItemInserted event in the aspx code, please check the code following:
<script runat="server"> protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { Response.Redirect("NewFolder1/WebForm1.aspx"); } </script>
Best Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, August 21, 2011 10:24 PM -
User735297519 posted
Hi Damon,
I have tried placing your latest script in both the Code Behind and in the Source Code and I have an Error "An End of Statement Expected" in both instances. I hope this gives you a clue for a solution.
Regards Ray
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 4:52 AM -
User-1694870838 posted
Hi Brown,
I'm sorry, I forgot you was using VB.NET, and you can check the code in your .apx page following:
<script runat ="server" >
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("WebForm1.aspx")
End Sub
</script>The WebForm1.aspx is another page which you need to add in project, the Button1_Click event generate via double click on the button in the design page.
If you use codebehind you just need to use code in the Button1_Click event as
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("WebForm1.aspx")
End SubBest Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 5:19 AM -
User-1694870838 posted
Hi,
If you didn't use Button Event, you can use DetailsView1_ItemInserted event. Double Click ItemInserted event of the events in DetailsView1 properties.
The WebForm1.aspx is another page which you need to add in project. Add codebehind following:Protected Sub DetailsView1_ItemInserted(sender As Object, e As DetailsViewInsertedEventArgs)
Response.Redirect("WebForm1.aspx")
End SubBest Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 8:16 PM
All replies
-
User1644485212 posted
If this is asp.net vb code then you can not use [] in session variable name. Rather you havbe to use ()
'<%= Session("RecordID") %>
And also = sign inplace of #. # is used with database fields.
Monday, August 8, 2011 2:20 PM -
User735297519 posted
Hi
Thanks for your observation, I have made the correction that removed the Error Message. My problem now is that the code '<%= Session("RecordID") %>' is now displayed in the texbox. I magine their is some "code behind" required to finally display the content of the session variable.
Your contribution was most helpful, I should have noticed it, as I am more familiar with Classic ASP than ASP.NET.
Monday, August 8, 2011 2:56 PM -
User1644485212 posted
try if it works without = sign
<% session["varname"]%>
Tuesday, August 9, 2011 9:45 AM -
User1644485212 posted
Or try to write in "" rather then '' i have tried in c# code is working perfatly.
Tuesday, August 9, 2011 9:55 AM -
User735297519 posted
Thank you for your Mails, the '<%= Session("RecordID") %>' the "=" was a typo error.
I have tried your other suggestions without success. I am begining to loose heart. I have spent many hours without success. I have picked up on two similar examples, that I have tried to re-create, but have come to nothing, probably a different enviroment.
Unfortunately I am not familiar with #C.
If you have any other suggestions please respond on the forum.
Tuesday, August 9, 2011 3:54 PM -
User-1694870838 posted
Hi,
Please refer to the code following:
public void @__DataBinding__control17(object sender, System.EventArgs e)
{
TextBox dataBindingExpressionBuilderTarget;
IDataItemContainer Container;
dataBindingExpressionBuilderTarget = ((TextBox)(sender));
Container = ((IDataItemContainer)(dataBindingExpressionBuilderTarget.BindingContainer));
if ((this.Page.GetDataItem() != null)) {
dataBindingExpressionBuilderTarget.Text = Convert.ToString(this.Eval("Name"), CultureInfo.CurrentCulture);
}
}
could you please give us your more code in the forum so that we can help you as soon as possible?
Best Regards,
Damon
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 11, 2011 11:57 PM -
User735297519 posted
I appreciate you interest in trying to helpme, I have limited knowledge of asp.net but anxious to learn. You will observe I have been using "Code Behind". I have not used the "Code Behind" in this case, I hope I have provided all the necessary code.
My request should have included in the Title "ASP.NET DETAILSVIEW Insert, for which I apologise.
<form id="form1" runat
="server">
<div style="height: 606px">
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString5 %>"
InsertCommand="INSERT INTO Members (RecordID) VALUES(@RecordID)"
SelectCommand="SELECT RecordID FROM Members WHERE RecordID=@RecordID">
<SelectParameters>
<asp:SessionParameter Name="RecordID" SessionField="RecordID" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="RecordID" />
</InsertParameters>
</asp:SqlDataSource>
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px"
style="z-index: 1; left: 363px; top: 200px; position: absolute; height: 67px; width: 125px"
Width="125px">
<Fields>
<asp:TemplateField HeaderText="RecordID" SortExpression="RecordID">
<InsertItemTemplate>
<asp:TextBox ID="RecordID" runat="server" Text='<%# Bind("RecordID") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RecordID") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Font-Bold="False" />
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</div>
<p>
</p>
</form>
Regards Ray
Friday, August 12, 2011 3:45 AM -
User-1694870838 posted
Hi,
I'm sorry for reply later!
From your code, you have a error on Text='<%# Session["RecordrID"]%>', in the VB you can use it like <asp:TextBox ID="TextBox1" runat="server" Text='<%# Session("RecordrID")%>'></asp:TextBox>, it is a () not [].
Best Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2011 3:21 AM -
User735297519 posted
Hi Damon,
I have made all your recommendations. the Session Variable now displays in the Textbox1, located in the InsertItemTemplate.
When I press the Insert Key, the error indicates that the value reaching the DBase is a Null, although it is displayed in the DetailsView as a numeric determined by the Session Variable. I hope you can come up with a solution.
Regards Ray
Thursday, August 18, 2011 6:19 PM -
User-1694870838 posted
Hi Brown,
Do you mean that you want to insert Session[RecordID] value into DBase?
Please check your code :InsertCommand="INSERT INTO Members (RecordID) VALUES(@RecordID)". From your details, the @RecordID is Null, I think you can pass value like : <InsertParameters>
<asp:SessionParameter name="SessionID" SessionField="SessionID"/>
</InsertParameters>Best Regards,
Damon
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 19, 2011 1:19 AM -
User1927273029 posted
Hello,
Use <%= Session["RecordID"] %> instead of <%# Session["RecordID"] %>
It will resolve the error.
Hope it helps.
Friday, August 19, 2011 2:59 AM -
User735297519 posted
Hi,
Thank you for your response, an earlier reply 08-08-2011 06:20 PM pointed this out, unfortunately it was a typographical error.
The variable displays but when the INSERT key is pressed I get an error indicating that a variable is a NULL.
Rgds Ray
Friday, August 19, 2011 6:44 AM -
User-952121411 posted
The HTML Insert Code is as follows: I have no code behind.
I know I am coming in late, but is there some reason you can not, or do not want to use a code behind file? The problem is, when you begin to place so much server-side code in the markup, the syntax begins to get quite tricky as you have already seen. In regards to your last post, checking if the session value is NULL prior to doing the INSERT is a lot easier in code than trying to inject the server tags in the markup.
cmd.Parameters.AddWithValue("@MyParam", IIf(Session("MyValue") IsNot Nothing, Session("MyValue").ToString, System.DBNull.Value))
Friday, August 19, 2011 4:50 PM -
User735297519 posted
Hi,
Thank you for your latest suggestion, I am pleased to say that having included your recommendation "<InsertParameters> <asp:SessionParameter name="SessionID" SessionField="SessionID"/> </InsertParameters> ", I have achievied my original objective thanks to your contribution.
The success resulted in an unexpected problem. When I press the INSERT key the data is transmitted to the database, then the program returns back to the DetailsView with the variable in the textbox. I had expected to intercept the program with "isPostback", unfortunately the program "FIRES" and proceeds to my other script before writing to the DBase. I would appreciate your suggestions on how to overcome this problem.
Unfortunately I am quite new to the ASP.NET technology and am trying to understand the Code Behind Event handling control scripts.
Regards Ray
Sunday, August 21, 2011 4:15 AM -
User-1694870838 posted
Hi Brown ,
I'm sorry for my reply late, because of weekends.
From you details, you want to direct to another page after inserting data into DBase, you can add ItemInserted event in the aspx code, please check the code following:
<script runat="server"> protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { Response.Redirect("NewFolder1/WebForm1.aspx"); } </script>
Best Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, August 21, 2011 10:24 PM -
User735297519 posted
Hi Damon,
I have tried placing your latest script in both the Code Behind and in the Source Code and I have an Error "An End of Statement Expected" in both instances. I hope this gives you a clue for a solution.
Regards Ray
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 4:52 AM -
User-1694870838 posted
Hi Brown,
I'm sorry, I forgot you was using VB.NET, and you can check the code in your .apx page following:
<script runat ="server" >
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("WebForm1.aspx")
End Sub
</script>The WebForm1.aspx is another page which you need to add in project, the Button1_Click event generate via double click on the button in the design page.
If you use codebehind you just need to use code in the Button1_Click event as
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect("WebForm1.aspx")
End SubBest Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 5:19 AM -
User735297519 posted
Hi Damon,
Thank for your quick response. When I saw your code an item that throws me is, the button that I am pressing is the INSERT and i am assuming you are considering this Button as Button1, otherwise where does Button1 originate?.
When I put your code in the Code Behind, The Button1 expression has a red line underside indicating an error, The error message is
"Handles clause requires WithEvents Variable defined in the containing type or one of its base types"
Regrds Ray
Monday, August 22, 2011 10:36 AM -
User-1694870838 posted
Hi,
If you didn't use Button Event, you can use DetailsView1_ItemInserted event. Double Click ItemInserted event of the events in DetailsView1 properties.
The WebForm1.aspx is another page which you need to add in project. Add codebehind following:Protected Sub DetailsView1_ItemInserted(sender As Object, e As DetailsViewInsertedEventArgs)
Response.Redirect("WebForm1.aspx")
End SubBest Regards,
Damon- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 22, 2011 8:16 PM -
User735297519 posted
Hi Damon,
Thank you again, I am pleased to say I fixed the problem last night. It was a useful exercise for me to understand the way to create & understand how to create the CODE BEHIND code. I am greatful to you for the support and ideas you have provided for me.
I hope if I have difficulties in the future you might pick up my query.
This case can be closed with a satisfactory solution complete.
Best of Luck Ray
Tuesday, August 23, 2011 4:16 AM -
User-1694870838 posted
Hi Brown,
I'm glad to hear you have got solution of the issue, I will aways spare no effort on your issue whenever you need my help. It's my pleasure!
Best Regards,
DamonTuesday, August 23, 2011 4:54 AM