Showing posts with label loads. Show all posts
Showing posts with label loads. Show all posts

Saturday, March 31, 2012

Set a session variable to pre defined value

I just want to set a sesison variable to a defined value when a page loads, I've tried the following but it doesn't seem to work. Any ideas where I'm going wrong?

<%# Session("var1") = "abc" %
Thanks

Julian ParkinsonYou've used adata binding expression, so it will only be called when DataBind() is called on the Page.

I think you want to use aninline code expression instead:

<% Session("var1") = "abc" %>

Hi,

You need to put the Session variable in the Page_Load like this:


if(!Page.IsPostBack)
{

Session["Name"] = "NewValue";
Response.Redirect("Mynewpage.aspx");

}

And then in the Mynewpage.aspx you can recieve the session using this code in the Page_Load with not postback.

if(Session["Name"] == null )
Response.Redirect("LoginPage.aspx");

else
Label1.Text = Session["Name"].ToString();


Dan,

Cheers for that. I just needed the remove the hash!! Duhh!

I'm moving from asp vb to asp.net vb and i'm finding it strange, some stuff is the same, some isn't sometimes I can't see the wood for the trees.

Thanks again.

set ASP.NET datagrid image based on SQL table value

I have an ASP.NET datagrid that loads an image. I would like to load
one image if the value in my SQL table is true and another if it is
false. Here is my code.
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
<!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="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3"
AutoGenerateColumns="False" CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<Columns>
</asp:BoundColumn>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<img src='\Check.gif'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.
Thaks for any help, This ASP.NET is kicking my butt.Hi Rob,
Just jam a little
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
in there and you should be okay.
BTW, I had some problems with your markup. My fixed version is below.
Does this help?
Ken
Microsoft MVP [ASP.NET]
Toronto
<!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="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" runat="server" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3" AutoGenerateColumns="False"
CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.com...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!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="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
BTW, here's the code behind and data source that I used for that example.
"Boolean" is the name of the field as well as the type.
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyGrid.DataSource = CreateDataSource()
MyGrid.DataBind()
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("City", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.com...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!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="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
Thanks, Thats just what I needed.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

set ASP.NET datagrid image based on SQL table value

I have an ASP.NET datagrid that loads an image. I would like to load
one image if the value in my SQL table is true and another if it is
false. Here is my code.

<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
<!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="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3"
AutoGenerateColumns="False" CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510"
BackColor="#F7DFB5"></FooterStyle>
<Columns>
</asp:BoundColumn>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<img src='\Check.gif'>
</ItemTemplate>
</asp:TemplateColumn
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML
I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.

Thaks for any help, This ASP.NET is kicking my butt.Hi Rob,

Just jam a little

<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'
in there and you should be okay.

BTW, I had some problems with your markup. My fixed version is below.

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

<!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="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="VBScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" runat="server" BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px"
BackColor="#DEBA84" CellPadding="3" AutoGenerateColumns="False"
CellSpacing="2">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#738A9C"></SelectedItemStyle>
<ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#A55129"></HeaderStyle>
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Check or X">
<ItemTemplate>
<IMG src='<%#iif(DataBinder.Eval(Container,
"DataItem.Boolean"),"Check.gif","x.gif") %>'>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML
"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.c om...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!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="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
BTW, here's the code behind and data source that I used for that example.
"Boolean" is the name of the field as well as the type.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
MyGrid.DataSource = CreateDataSource()
MyGrid.DataBind()

End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("City", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

"Rob Rogers" <rob@.natltc.com> wrote in message
news:7ee34208.0407141234.18d2abdd@.posting.google.c om...
>I have an ASP.NET datagrid that loads an image. I would like to load
> one image if the value in my SQL table is true and another if it is
> false. Here is my code.
> <%@. Page Language="vb" AutoEventWireup="false"
> Codebehind="Search.aspx.vb" Inherits="PROJECT.WebForm1"%>
> <!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="Visual Basic .NET 7.1">
> <meta name="vs_defaultClientScript" content="VBScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
> absolute; TOP: 0px" runat="server"
> BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
> BackColor="#DEBA84" CellPadding="3"
> AutoGenerateColumns="False" CellSpacing="2">
> <SelectedItemStyle Font-Bold="True" ForeColor="White"
> BackColor="#738A9C"></SelectedItemStyle>
> <ItemStyle ForeColor="#8C4510" BackColor="#FFF7E7"></ItemStyle>
> <HeaderStyle Font-Bold="True" ForeColor="White"
> BackColor="#A55129"></HeaderStyle>
> <FooterStyle ForeColor="#8C4510"
> BackColor="#F7DFB5"></FooterStyle>
> <Columns>
> </asp:BoundColumn>
> <asp:BoundColumn DataField="City" ReadOnly="True" HeaderText="City">
> <ItemStyle Width="150px"></ItemStyle>
> </asp:BoundColumn>
> <asp:TemplateColumn HeaderText="Check or X">
> <ItemTemplate>
> <img src='\Check.gif'>
> </ItemTemplate>
> </asp:TemplateColumn>
>
> </Columns>
> <PagerStyle HorizontalAlign="Center" ForeColor="#8C4510"
> Mode="NumericPages"></PagerStyle>
> </asp:DataGrid>
> </form>
> </body>
> </HTML>
> I want to show the 'Check.gif' if an SQL table value is True or
> 'x.gif' if it is false.
> Thaks for any help, This ASP.NET is kicking my butt.
Thanks, Thats just what I needed.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Saturday, March 24, 2012

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page loads, I need the focus to be on one of the textboxes called txtUserName.

I come from a VB background, so expecting the obvious, I go to the Page_Load event of the index.aspx page and try to write txtUserName.SetFocus but I see there isn't a SetFocus method for the System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in ASP.NET?take a look at this thread:

http://www.vbforums.com/showthread.php?t=316582&highlight=textbox+focus
Hi , You may use a java script

<SCRIPT LANGUAGE="JavaScript">
function setFocus()
{
document.Form1('TxtCno').focus()
}
</SCRIPT>

and call it in

<body MS_POSITIONING="GridLayout" bgColor="#003366" onload="setFocus();">


thats it it will focus the cursor on your desired field