Saturday, March 31, 2012
Set a value to a hidden field in a web page
I have a problem when using a hidden field to send a value to the server.
Below you can see my code in simplyfied versions.
What I'm trying to do is:
1. The user browses for a picture at the network from their computer using
control File1.
2. The user clickes the button Commit picture (with id CliBtn)
a. The script is running at the client to get the sharename of the file
selected
b. The script should update a picture shown (the code below just shows
the label with the path)
c. The code-behind should then save all values in a database.
The problem appear when I'm trying to set the value to the hide control, so
I am doing something wrong.
I'm not so used to web developing, so please give me some help here, with
code please.
Regards Magnus
--
Code-behind page in C#
--
void Page_Load(object sender, EventArgs e)
{
HtmlInputHidden hide = new HtmlInputHidden();
hide.ID = "hide";
hide.Value = "Hidden Text";
sURL = Request.Form["hide"].ToString();
Label11.Text = sURL;
}
--
.ASPX page
--
<head>
<title>Untitled Page</title>
<script language=vbscript>
function getpicvb()
dim javatext
javatext = document.getElementById("File1").getAttribute("value")
dim fso
set FSO = CreateObject("Scripting.FileSystemObject")
dim drive
set drive =
FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathName(javatext)))
javatext = drive.ShareName
'hide.value = javatext ' this row doesn't work
alert(javatext)
end function
</script>
</head>
<body>
<input id="File1" type="file" />
<input id="CliBtn" value="Commit picture" onclick="getpicvb() " type=submit
/>
<asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
<input type=hidden id=hide />
</body>
----
---
"Brock Allen" <ballen@dotnet.itags.org.NOSPAMdevelop.com> wrote in message
news:444437632489320772241920@dotnet.itags.org.msnews.microsoft.com...
> Make a hidden field (via Page.RegisterHiddenField) and have the javascript
> write the value to the hidden. In the server, fetch the value via
Request.Form["YourFieldID"]
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
>Controlled envionement ? What is the exact problme you have (you have always
"Hidden Text" server side ?
In particular fso is not supposed to work without tweaking security
settings. ARe you sure itjust doesn't fails silently...
Also you always change the value of the "hide" field when the page loads...
Try to do not "if (!Ispostback)"...
Patrice
"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a problem when using a hidden field to send a value to the server.
> Below you can see my code in simplyfied versions.
> What I'm trying to do is:
> 1. The user browses for a picture at the network from their computer using
> control File1.
> 2. The user clickes the button Commit picture (with id CliBtn)
> a. The script is running at the client to get the sharename of the
file
> selected
> b. The script should update a picture shown (the code below just shows
> the label with the path)
> c. The code-behind should then save all values in a database.
> The problem appear when I'm trying to set the value to the hide control,
so
> I am doing something wrong.
> I'm not so used to web developing, so please give me some help here, with
> code please.
> Regards Magnus
> --
> Code-behind page in C#
> --
> void Page_Load(object sender, EventArgs e)
> {
> HtmlInputHidden hide = new HtmlInputHidden();
> hide.ID = "hide";
> hide.Value = "Hidden Text";
> sURL = Request.Form["hide"].ToString();
> Label11.Text = sURL;
> }
> --
> .ASPX page
> --
> <head>
> <title>Untitled Page</title>
> <script language=vbscript>
> function getpicvb()
> dim javatext
> javatext = document.getElementById("File1").getAttribute("value")
> dim fso
> set FSO = CreateObject("Scripting.FileSystemObject")
> dim drive
> set drive =
> FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathName(javatext)))
> javatext = drive.ShareName
> 'hide.value = javatext ' this row doesn't work
> alert(javatext)
> end function
> </script>
> </head>
> <body>
> <input id="File1" type="file" />
> <input id="CliBtn" value="Commit picture" onclick="getpicvb() "
type=submit
> />
> <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> <input type=hidden id=hide />
> </body>
> ----
--
> ---
> "Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
> news:444437632489320772241920@.msnews.microsoft.com...
javascript
> Request.Form["YourFieldID"]
>
>
Magnus what are u trying to do'
Vbscript,C#'?
*** Sent via Developersdex http://www.examnotes.net ***
Hello and thanks for your answer.
Well, I thought fso was not a common way to solve this, but since this is
for a Intranet, I think I can theak the security anyway. If you have a
better solution for this issue I'll be glad to here it.
I'm not sure what silent failure does mean, but I think that is what I get.
I get no error message, but the alert row is never executed when the
hide.value = javatext is run.
The problem does not appear when working with fso. It appears when trying to
set the hide object.
I am familiar to the (!IsPostBack) command, so I will take care of that in
my full code.
My code in this forum is shrinked.
Regards Magnus
"Patrice" <nobody@.nowhere.com> wrote in message
news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> Controlled envionement ? What is the exact problme you have (you have
always
> "Hidden Text" server side ?
> In particular fso is not supposed to work without tweaking security
> settings. ARe you sure itjust doesn't fails silently...
> Also you always change the value of the "hide" field when the page
loads...
> Try to do not "if (!Ispostback)"...
> Patrice
> --
> "Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
> news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
server.
using
> file
shows
> so
with
document.getElementById("File1").getAttribute("value")
> type=submit
> ----
> --
> javascript
This
basics?
>
Ok, so this line is never executed.
Check if the fso object is set. Do you have yet tweaked security ?
If I remember when security is not tweaked , it fails without any warning
(as anyway it 's not supposed to work).
What do you want to do ? You can use an input type=file to get the name
server side even if you don't want to upload this file. This way you
wouldn't need to copy this value in an hidden field.
Also I don't really see how it works. The server could perhaps not have the
same netwrok path available.
Depneidng on what you wan to do with this file, I would upload it server
file to do the intended processing...
Good luck
Patrice
"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:%23GCvfKPQFHA.3988@.tk2msftngp13.phx.gbl...
> Hello and thanks for your answer.
> Well, I thought fso was not a common way to solve this, but since this is
> for a Intranet, I think I can theak the security anyway. If you have a
> better solution for this issue I'll be glad to here it.
> I'm not sure what silent failure does mean, but I think that is what I
get.
> I get no error message, but the alert row is never executed when the
> hide.value = javatext is run.
> The problem does not appear when working with fso. It appears when trying
to
> set the hide object.
> I am familiar to the (!IsPostBack) command, so I will take care of that in
> my full code.
> My code in this forum is shrinked.
> Regards Magnus
>
> "Patrice" <nobody@.nowhere.com> wrote in message
> news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> always
> loads...
de
> server.
> using
> shows
control,
> with
> document.getElementById("File1").getAttribute("value")
> ----
> This
> basics?
>
Set a value to a hidden field in a web page
I have a problem when using a hidden field to send a value to the server.
Below you can see my code in simplyfied versions.
What I'm trying to do is:
1. The user browses for a picture at the network from their computer using
control File1.
2. The user clickes the button Commit picture (with id CliBtn)
a. The script is running at the client to get the sharename of the file
selected
b. The script should update a picture shown (the code below just shows
the label with the path)
c. The code-behind should then save all values in a database.
The problem appear when I'm trying to set the value to the hide control, so
I am doing something wrong.
I'm not so used to web developing, so please give me some help here, with
code please.
Regards Magnus
--------
Code-behind page in C#
--------
void Page_Load(object sender, EventArgs e)
{
HtmlInputHidden hide = new HtmlInputHidden();
hide.ID = "hide";
hide.Value = "Hidden Text";
sURL = Request.Form["hide"].ToString();
Label11.Text = sURL;
}
--------
..ASPX page
--------
<head>
<title>Untitled Page</title>
<script language=vbscript>
function getpicvb()
dim javatext
javatext = document.getElementById("File1").getAttribute("value")
dim fso
set FSO = CreateObject("Scripting.FileSystemObject")
dim drive
set drive =
FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathN ame(javatext)))
javatext = drive.ShareName
'hide.value = javatext ' this row doesn't work
alert(javatext)
end function
</script>
</head>
<body>
<input id="File1" type="file" />
<input id="CliBtn" value="Commit picture" onclick="getpicvb() " type=submit
/>
<asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
<input type=hidden id=hide />
</body>
-----------------------
---------------
"Brock Allen" <ballen@dotnet.itags.org.NOSPAMdevelop.com> wrote in message
news:444437632489320772241920@dotnet.itags.org.msnews.microsoft.com ...
> Make a hidden field (via Page.RegisterHiddenField) and have the javascript
> write the value to the hidden. In the server, fetch the value via
Request.Form["YourFieldID"]
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
> > Hello!
> > I have a client javascript that generates a string (like below). This
> > string should then be used by server code (in this case a function
> > called run).
> > <script language=javascript>
> > function getpic()
> > { string s;
> > s = document.getElementById("File1").getAttribute("value");
> > <% run(s); %>
> > }
> > I think this would be rather common, so maybe I'm missing some basics?
> > Regards MagnusControlled envionement ? What is the exact problme you have (you have always
"Hidden Text" server side ?
In particular fso is not supposed to work without tweaking security
settings. ARe you sure itjust doesn't fails silently...
Also you always change the value of the "hide" field when the page loads...
Try to do not "if (!Ispostback)"...
Patrice
--
"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a problem when using a hidden field to send a value to the server.
> Below you can see my code in simplyfied versions.
> What I'm trying to do is:
> 1. The user browses for a picture at the network from their computer using
> control File1.
> 2. The user clickes the button Commit picture (with id CliBtn)
> a. The script is running at the client to get the sharename of the
file
> selected
> b. The script should update a picture shown (the code below just shows
> the label with the path)
> c. The code-behind should then save all values in a database.
> The problem appear when I'm trying to set the value to the hide control,
so
> I am doing something wrong.
> I'm not so used to web developing, so please give me some help here, with
> code please.
> Regards Magnus
> --------
> Code-behind page in C#
> --------
> void Page_Load(object sender, EventArgs e)
> {
> HtmlInputHidden hide = new HtmlInputHidden();
> hide.ID = "hide";
> hide.Value = "Hidden Text";
> sURL = Request.Form["hide"].ToString();
> Label11.Text = sURL;
> }
> --------
> .ASPX page
> --------
> <head>
> <title>Untitled Page</title>
> <script language=vbscript>
> function getpicvb()
> dim javatext
> javatext = document.getElementById("File1").getAttribute("value")
> dim fso
> set FSO = CreateObject("Scripting.FileSystemObject")
> dim drive
> set drive =
> FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathN ame(javatext)))
> javatext = drive.ShareName
> 'hide.value = javatext ' this row doesn't work
> alert(javatext)
> end function
> </script>
> </head>
> <body>
> <input id="File1" type="file" />
> <input id="CliBtn" value="Commit picture" onclick="getpicvb() "
type=submit
> />
> <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> <input type=hidden id=hide />
> </body>
> -----------------------
--
> ---------------
> "Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
> news:444437632489320772241920@.msnews.microsoft.com ...
> > Make a hidden field (via Page.RegisterHiddenField) and have the
javascript
> > write the value to the hidden. In the server, fetch the value via
> Request.Form["YourFieldID"]
> > -Brock
> > DevelopMentor
> > http://staff.develop.com/ballen
> > > Hello!
> > > > I have a client javascript that generates a string (like below). This
> > > string should then be used by server code (in this case a function
> > > called run).
> > > > <script language=javascript>
> > > function getpic()
> > > { string s;
> > > s = document.getElementById("File1").getAttribute("value");
> > > <% run(s); %>
> > > }
> > > I think this would be rather common, so maybe I'm missing some basics?
> > > Regards Magnus
>
Magnus what are u trying to do??
Vbscript,C#???
*** Sent via Developersdex http://www.developersdex.com ***
Hello and thanks for your answer.
Well, I thought fso was not a common way to solve this, but since this is
for a Intranet, I think I can theak the security anyway. If you have a
better solution for this issue I'll be glad to here it.
I'm not sure what silent failure does mean, but I think that is what I get.
I get no error message, but the alert row is never executed when the
hide.value = javatext is run.
The problem does not appear when working with fso. It appears when trying to
set the hide object.
I am familiar to the (!IsPostBack) command, so I will take care of that in
my full code.
My code in this forum is shrinked.
Regards Magnus
"Patrice" <nobody@.nowhere.com> wrote in message
news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> Controlled envionement ? What is the exact problme you have (you have
always
> "Hidden Text" server side ?
> In particular fso is not supposed to work without tweaking security
> settings. ARe you sure itjust doesn't fails silently...
> Also you always change the value of the "hide" field when the page
loads...
> Try to do not "if (!Ispostback)"...
> Patrice
> --
> "Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
> news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> > Hello!
> > I have a problem when using a hidden field to send a value to the
server.
> > Below you can see my code in simplyfied versions.
> > What I'm trying to do is:
> > 1. The user browses for a picture at the network from their computer
using
> > control File1.
> > 2. The user clickes the button Commit picture (with id CliBtn)
> > a. The script is running at the client to get the sharename of the
> file
> > selected
> > b. The script should update a picture shown (the code below just
shows
> > the label with the path)
> > c. The code-behind should then save all values in a database.
> > The problem appear when I'm trying to set the value to the hide control,
> so
> > I am doing something wrong.
> > I'm not so used to web developing, so please give me some help here,
with
> > code please.
> > Regards Magnus
> > --------
> > Code-behind page in C#
> > --------
> > void Page_Load(object sender, EventArgs e)
> > {
> > HtmlInputHidden hide = new HtmlInputHidden();
> > hide.ID = "hide";
> > hide.Value = "Hidden Text";
> > sURL = Request.Form["hide"].ToString();
> > Label11.Text = sURL;
> > }
> > --------
> > .ASPX page
> > --------
> > <head>
> > <title>Untitled Page</title>
> > <script language=vbscript>
> > function getpicvb()
> > dim javatext
> > javatext =
document.getElementById("File1").getAttribute("value")
> > dim fso
> > set FSO = CreateObject("Scripting.FileSystemObject")
> > dim drive
> > set drive =
> > FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathN ame(javatext)))
> > javatext = drive.ShareName
> > 'hide.value = javatext ' this row doesn't work
> > alert(javatext)
> > end function
> > </script>
> > </head>
> > <body>
> > <input id="File1" type="file" />
> > <input id="CliBtn" value="Commit picture" onclick="getpicvb() "
> type=submit
> > />
> > <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> > <input type=hidden id=hide />
> > </body>
> -----------------------
> --
> > ---------------
> > "Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
> > news:444437632489320772241920@.msnews.microsoft.com ...
> > > Make a hidden field (via Page.RegisterHiddenField) and have the
> javascript
> > > write the value to the hidden. In the server, fetch the value via
> > Request.Form["YourFieldID"]
> > > > -Brock
> > > DevelopMentor
> > > http://staff.develop.com/ballen
> > > > > > > Hello!
> > > > > > I have a client javascript that generates a string (like below).
This
> > > > string should then be used by server code (in this case a function
> > > > called run).
> > > > > > <script language=javascript>
> > > > function getpic()
> > > > { string s;
> > > > s = document.getElementById("File1").getAttribute("value");
> > > > <% run(s); %>
> > > > }
> > > > I think this would be rather common, so maybe I'm missing some
basics?
> > > > Regards Magnus
> > > > >
Ok, so this line is never executed.
Check if the fso object is set. Do you have yet tweaked security ?
If I remember when security is not tweaked , it fails without any warning
(as anyway it 's not supposed to work).
What do you want to do ? You can use an input type=file to get the name
server side even if you don't want to upload this file. This way you
wouldn't need to copy this value in an hidden field.
Also I don't really see how it works. The server could perhaps not have the
same netwrok path available.
Depneidng on what you wan to do with this file, I would upload it server
file to do the intended processing...
Good luck
Patrice
--
"Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message de
news:%23GCvfKPQFHA.3988@.tk2msftngp13.phx.gbl...
> Hello and thanks for your answer.
> Well, I thought fso was not a common way to solve this, but since this is
> for a Intranet, I think I can theak the security anyway. If you have a
> better solution for this issue I'll be glad to here it.
> I'm not sure what silent failure does mean, but I think that is what I
get.
> I get no error message, but the alert row is never executed when the
> hide.value = javatext is run.
> The problem does not appear when working with fso. It appears when trying
to
> set the hide object.
> I am familiar to the (!IsPostBack) command, so I will take care of that in
> my full code.
> My code in this forum is shrinked.
> Regards Magnus
>
> "Patrice" <nobody@.nowhere.com> wrote in message
> news:#Xio4aOQFHA.3076@.TK2MSFTNGP14.phx.gbl...
> > Controlled envionement ? What is the exact problme you have (you have
> always
> > "Hidden Text" server side ?
> > In particular fso is not supposed to work without tweaking security
> > settings. ARe you sure itjust doesn't fails silently...
> > Also you always change the value of the "hide" field when the page
> loads...
> > Try to do not "if (!Ispostback)"...
> > Patrice
> > --
> > "Magnus Blomberg" <magnus.blomberg@.skanska.se> a crit dans le message
de
> > news:uTXsgPOQFHA.1528@.TK2MSFTNGP09.phx.gbl...
> > > Hello!
> > > > I have a problem when using a hidden field to send a value to the
> server.
> > > Below you can see my code in simplyfied versions.
> > > > What I'm trying to do is:
> > > 1. The user browses for a picture at the network from their computer
> using
> > > control File1.
> > > 2. The user clickes the button Commit picture (with id CliBtn)
> > > a. The script is running at the client to get the sharename of the
> > file
> > > selected
> > > b. The script should update a picture shown (the code below just
> shows
> > > the label with the path)
> > > c. The code-behind should then save all values in a database.
> > > > The problem appear when I'm trying to set the value to the hide
control,
> > so
> > > I am doing something wrong.
> > > I'm not so used to web developing, so please give me some help here,
> with
> > > code please.
> > > > Regards Magnus
> > > --------
> > > Code-behind page in C#
> > > --------
> > > void Page_Load(object sender, EventArgs e)
> > > {
> > > HtmlInputHidden hide = new HtmlInputHidden();
> > > hide.ID = "hide";
> > > hide.Value = "Hidden Text";
> > > sURL = Request.Form["hide"].ToString();
> > > Label11.Text = sURL;
> > > }
> > > --------
> > > .ASPX page
> > > --------
> > > <head>
> > > <title>Untitled Page</title>
> > > <script language=vbscript>
> > > function getpicvb()
> > > dim javatext
> > > javatext =
> document.getElementById("File1").getAttribute("value")
> > > dim fso
> > > set FSO = CreateObject("Scripting.FileSystemObject")
> > > dim drive
> > > set drive =
> > > FSO.GetDrive(FSO.GetDriveName(FSO.GetAbsolutePathN ame(javatext)))
> > > javatext = drive.ShareName
> > > 'hide.value = javatext ' this row doesn't work
> > > alert(javatext)
> > > end function
> > > </script>
> > > </head>
> > > <body>
> > > <input id="File1" type="file" />
> > > <input id="CliBtn" value="Commit picture" onclick="getpicvb() "
> > type=submit
> > > />
> > > <asp:Label ID="Label11" Runat="server" Text="Label"></asp:Label>
> > > <input type=hidden id=hide />
> > > </body>
> -----------------------
> > --
> > > ---------------
> > > "Brock Allen" <ballen@.NOSPAMdevelop.com> wrote in message
> > > news:444437632489320772241920@.msnews.microsoft.com ...
> > > > Make a hidden field (via Page.RegisterHiddenField) and have the
> > javascript
> > > > write the value to the hidden. In the server, fetch the value via
> > > Request.Form["YourFieldID"]
> > > > > > -Brock
> > > > DevelopMentor
> > > > http://staff.develop.com/ballen
> > > > > > > > > > > Hello!
> > > > > > > > I have a client javascript that generates a string (like below).
> This
> > > > > string should then be used by server code (in this case a function
> > > > > called run).
> > > > > > > > <script language=javascript>
> > > > > function getpic()
> > > > > { string s;
> > > > > s = document.getElementById("File1").getAttribute("value");
> > > > > <% run(s); %>
> > > > > }
> > > > > I think this would be rather common, so maybe I'm missing some
> basics?
> > > > > Regards Magnus
> > > > > > > > > > > >
Thursday, March 29, 2012
Set checkbox in datagrid manually/through code
false. I am trying to populate a checkbox in a datagrid. In my SQL
statement, I used the Decode function so that when it populates the
dataset that I would store the string 'true' and 'false' rather than a
numeric value. I did this because I thought it would make it easier
to actually set the value in the checkbox. Anyway, I bind the dataset
to the datagrid. In my HTML code, the checkbox is contained in a
templatecolumn:
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%#
(bool) DataBinder.Eval(Container.DataItem,
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox
However, this will not work. It complains that "Specified cast is not
valid."
I have even tried it without the "(bool)" cast and it still didn't
work.
The data in my database has the value stored as either a -1 or 0. In
either case, I just want to set the check box to checked or unchecked.
I was even wondering if I needed to use one of the d atagrid's events
to do this.
Any ideas or help is appreciated.
Thanks,
MartySome suggestions
Try using a helper function to interpret your -1 or 0 instead of adjusting your recordset to return true or false
In your codebehind
protected bool GetCheckBoxSetting(object myObj
int myInt = Convert.ToInt16(myObj)
return (myInt == -1)
Then in your aspx
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
GetCheckBoxSetting(DataBinder.Eval(Container.DataI tem, "strainer_on_fuel_line_bool")) %>' Enabled="False"></asp:CheckBox
If returning bool doesn't set the checkbox checked property correctly then try returning a string from GetCheckBoxSetting method
protected string GetCheckBoxSetting(object myObj
int myInt = Convert.ToInt16(myObj)
if (myInt == -1
return "true"
els
return "false"
HTH
Suresh
-- Marty wrote: --
I have a numeric Oracle field which stores -1 for true and 0 fo
false. I am trying to populate a checkbox in a datagrid. In my SQ
statement, I used the Decode function so that when it populates th
dataset that I would store the string 'true' and 'false' rather than
numeric value. I did this because I thought it would make it easie
to actually set the value in the checkbox. Anyway, I bind the datase
to the datagrid. In my HTML code, the checkbox is contained in
templatecolumn
<asp:CheckBox id="chkStrainerFuelLine" runat="server" Checked='<%
(bool) DataBinder.Eval(Container.DataItem
"strainer_on_fuel_line_bool") %>' Enabled="False"></asp:CheckBox
However, this will not work. It complains that "Specified cast is no
valid.
I have even tried it without the "(bool)" cast and it still didn'
work
The data in my database has the value stored as either a -1 or 0. I
either case, I just want to set the check box to checked or unchecked
I was even wondering if I needed to use one of the d atagrid's event
to do this
Any ideas or help is appreciated
Thanks,
Mart
It worked, thanks!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Wednesday, March 28, 2012
set decimal value to right
Dear all,
I read my data through sqldatareader and then i use dataset to convert the data and bind it to gridview manually. There is one field in my data set is of decimal type. I found out that when it was displayed in the gridview, all of the columns are set to left hand side. Is it a way which I can move the decimal field to right hand side? FYI, there isn't any data source control involve there.
Thanks
Yes you need to change the GridView column for you decimal to be aligned to the right side. You can do this in the designer by clicking the arrow in the upper right hand side of the control.Hi, once I change it to right aligned, all of the other fields will become right aligned as well. Is it a way which I can only set that particular decimal field to right aligned and the rest of the text field remain left aligned?
Thanks
Problem solved
Great glad I could help, if I even helped at all.
Monday, March 26, 2012
Set default text on databound object
Since it is the insert template it really doesn't have anything in it.
How do I set the default text? Like for example if I have a insert
template field that is databound to a date sql column how can I set the
text to be a default like todays date?Use the ItemDataBound event. This event fires after the databinding occurs
for each Item, so it occurs the same number of times as the number of Items.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"MasterChief" <constants@.mix-net.net> wrote in message
news:1138744610.650024.116910@.o13g2000cwo.googlegroups.com...
>I have an insert template textbox that is bound to a field in SQL.
> Since it is the insert template it really doesn't have anything in it.
> How do I set the default text? Like for example if I have a insert
> template field that is databound to a date sql column how can I set the
> text to be a default like todays date?
>
I can't seem to find the ItemDataBound event. I can find it for the
gridview but not the formview which is where the insert template I am
using is. I am trying to use the databinding event is that the same
thing as ItemDataBound? Also how do I reference the textbox in the form
view? Like I can't see to go plan_startdateTextBox.text =
DateTime.Today.ToString()
Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
Object, ByVal e As System.EventArgs)
End Sub
I searched for hours and finally came upon this posting if anybody is
interested.
http://groups.google.com/group/micr...ae822433a4ab209
Here is an example from code that I wrote:
Private Sub datResults_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datResults.ItemDataBound
If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblRegion1"), Label).Text = "*NONE*" Then
CType(e.Item.FindControl("lblRegion1"), Label).Text = " "
End If
If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblRegion2"), Label).Text = "*NONE*" Then
CType(e.Item.FindControl("lblRegion2"), Label).Text = " "
End If
If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblPhone1"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone1"), Label).Text = " "
If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblPhone2"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone2"), Label).Text = " "
End Sub
Notice that at the end of the first line it refers to the event as
datResults.ItemDataBound (this is the standard objectID.eventname format).
As for your question about referencing a textbox (or any other Control used
in your Template), you must use
CType(e.Item.FindControl(controlID),ControlType) to reference the Control.
This is necessary because since there are many Items in a DataList (for
example, my example will include many controls with the ID lblPhone1), you
cannot simply use just the ID. All my sample code is in VB.NET, if you have
any questions let me know.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"MasterChief" <constants@.mix-net.net> wrote in message
news:1138911157.928679.158000@.g47g2000cwa.googlegroups.com...
>I can't seem to find the ItemDataBound event. I can find it for the
> gridview but not the formview which is where the insert template I am
> using is. I am trying to use the databinding event is that the same
> thing as ItemDataBound? Also how do I reference the textbox in the form
> view? Like I can't see to go plan_startdateTextBox.text =
> DateTime.Today.ToString()
> Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
> Object, ByVal e As System.EventArgs)
> End Sub
>
Set default text on databound object
Since it is the insert template it really doesn't have anything in it.
How do I set the default text? Like for example if I have a insert
template field that is databound to a date sql column how can I set the
text to be a default like todays date?Use the ItemDataBound event. This event fires after the databinding occurs
for each Item, so it occurs the same number of times as the number of Items.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"MasterChief" <constants@.mix-net.net> wrote in message
news:1138744610.650024.116910@.o13g2000cwo.googlegr oups.com...
>I have an insert template textbox that is bound to a field in SQL.
> Since it is the insert template it really doesn't have anything in it.
> How do I set the default text? Like for example if I have a insert
> template field that is databound to a date sql column how can I set the
> text to be a default like todays date?
I can't seem to find the ItemDataBound event. I can find it for the
gridview but not the formview which is where the insert template I am
using is. I am trying to use the databinding event is that the same
thing as ItemDataBound? Also how do I reference the textbox in the form
view? Like I can't see to go plan_startdateTextBox.text =
DateTime.Today.ToString()
Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
Object, ByVal e As System.EventArgs)
End Sub
I searched for hours and finally came upon this posting if anybody is
interested.
http://groups.google.com/group/micr...ae822433a4ab209
Here is an example from code that I wrote:
Private Sub datResults_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datResults.ItemDataBound
If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblRegion1"), Label).Text = "*NONE*" Then
CType(e.Item.FindControl("lblRegion1"), Label).Text = " "
End If
If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblRegion2"), Label).Text = "*NONE*" Then
CType(e.Item.FindControl("lblRegion2"), Label).Text = " "
End If
If e.Item.ItemType = ListItemType.Item AndAlso
CType(e.Item.FindControl("lblPhone1"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone1"), Label).Text = " "
If e.Item.ItemType = ListItemType.AlternatingItem AndAlso
CType(e.Item.FindControl("lblPhone2"), Label).Text = "" Then
CType(e.Item.FindControl("lblPhone2"), Label).Text = " "
End Sub
Notice that at the end of the first line it refers to the event as
datResults.ItemDataBound (this is the standard objectID.eventname format).
As for your question about referencing a textbox (or any other Control used
in your Template), you must use
CType(e.Item.FindControl(controlID),ControlType) to reference the Control.
This is necessary because since there are many Items in a DataList (for
example, my example will include many controls with the ID lblPhone1), you
cannot simply use just the ID. All my sample code is in VB.NET, if you have
any questions let me know.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"MasterChief" <constants@.mix-net.net> wrote in message
news:1138911157.928679.158000@.g47g2000cwa.googlegr oups.com...
>I can't seem to find the ItemDataBound event. I can find it for the
> gridview but not the formview which is where the insert template I am
> using is. I am trying to use the databinding event is that the same
> thing as ItemDataBound? Also how do I reference the textbox in the form
> view? Like I can't see to go plan_startdateTextBox.text =
> DateTime.Today.ToString()
> Protected Sub plan_startdateTextBox_DataBinding(ByVal sender As
> Object, ByVal e As System.EventArgs)
> End Sub
Set Email address as username
I am wanting to do something similar except I want to remove the UserName field as our database uses the email field to logon.
Of course I would just make the email field as UserName but it requires the email field as well.
So am I going to have to write my own provider just to remove one simple text box?
All help greatly appreciated :)
I used the ASP:Wizard control instead and used parameters to pass the values to the database. Thanks though.
ecbruck:
That seems like a lot of work just to use the email address as the username. Im doing the same thing in my current project, however i'm simply populating both fields with the entered email address. My suggestion would be to use the standard ASP.NET membership provider.
What event do you do this and do you have email validation and unique Username working? I was thinking of trying this myself but just using the stock Username and trying to get another validation control working on it for the email check.
That's exactly what I did. I set the UserName to be unique, and I added a RegularExpressionValidator to handle the email address validation. I'm not sure what you are asking in terms of an event, as everything else in the Membership Provider remains the same.
ok great thanks for the fast reply. I thought that you might have to override the event to add the reg exp validation.
Set Enabled to false for multiple web controls
I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}
Anyone can give me a hint?
ElaineOn May 23, 9:01 pm, elaine <elain...@.gmail.com> wrote:
> But there should be a easy way to do it
> like :
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
> }
> Anyone can give me a hint?
Sorry, I'm not clear on your question...
..do you mean that the for loop you wrote up there doesn't work ?
If it does, that seems fairly simple to me.. maybe I'd try to save a
line with:
foreach(Control ctrl in this.Controls)
ctrl.Enabled=false;
However, I don't think that the base Control class defines an Enabled
property, and that might be a problem. Then again, a Control might be
a label, a text literal, a generic html control, a bunch of things
were it's not quite clear what it means to be 'enabled' or not. Maybe
when 'enabled' is turned to false on your user control, you just don't
want to display any of its children controls ?
If so, at render time, you could check the value of the user control's
Enabled property:
if(this.Enabled)
base.Render(writer);
HTH,
~O
You could use control tree recursion to touch all the controls in the way
you describe.
Here are the details:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"elaine" <elain.sun@.gmail.com> wrote in message
news:1179968508.834610.110610@.n15g2000prd.googlegroups.com...
> Hi,
> I have a usercontrol which contains multiple server controls like
> textbox, radiobutton..., I have a public field in the usercontrol
> "Enabled". What i want to do is when the usercontrol's "Enabled" is
> set to false, set all its child controls "Enabled" to false. I know i
> can set them one by one. But there should be a easy way to do it
> like :
> for(int i=0;i<myUserControl.Controls.Count;i++)
> {
> control oControl = (control) myUserControl.Controls(i);
> oControl.Enabled = false;
> }
> Anyone can give me a hint?
> Elaine
>
Set Enabled to false for multiple web controls
I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}
Anyone can give me a hint?
ElaineOn May 23, 9:01 pm, elaine <elain...@.gmail.comwrote:
Quote:
Originally Posted by
But there should be a easy way to do it
like :
>
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
>
}
>
Anyone can give me a hint?
Sorry, I'm not clear on your question...
...do you mean that the for loop you wrote up there doesn't work ?
If it does, that seems fairly simple to me.. maybe I'd try to save a
line with:
foreach(Control ctrl in this.Controls)
ctrl.Enabled=false;
However, I don't think that the base Control class defines an Enabled
property, and that might be a problem. Then again, a Control might be
a label, a text literal, a generic html control, a bunch of things
were it's not quite clear what it means to be 'enabled' or not. Maybe
when 'enabled' is turned to false on your user control, you just don't
want to display any of its children controls ?
If so, at render time, you could check the value of the user control's
Enabled property:
if(this.Enabled)
base.Render(writer);
HTH,
~O
You could use control tree recursion to touch all the controls in the way
you describe.
Here are the details:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx
--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"elaine" <elain.sun@.gmail.comwrote in message
news:1179968508.834610.110610@.n15g2000prd.googlegr oups.com...
Quote:
Originally Posted by
Hi,
>
I have a usercontrol which contains multiple server controls like
textbox, radiobutton..., I have a public field in the usercontrol
"Enabled". What i want to do is when the usercontrol's "Enabled" is
set to false, set all its child controls "Enabled" to false. I know i
can set them one by one. But there should be a easy way to do it
like :
>
for(int i=0;i<myUserControl.Controls.Count;i++)
{
control oControl = (control) myUserControl.Controls(i);
oControl.Enabled = false;
}
>
Anyone can give me a hint?
>
Elaine
>
Set field to null
How can I set it to DBNull?
I have tried the following but It doesnt work.
You may try this:Dim updateSOrder As String = "Update SOrders set confirm_id = @dotnet.itags.org.confirmId where SOrder ='" & lblConfirmOrder.Text & "'"
Dim SaveDelete As SqlCommand
SaveDelete = New SqlCommand(updateSOrder, oConnection)Dim blank As DBNull
SaveDelete.Parameters.Add(New SqlParameter("@dotnet.itags.org.ConfirmId", SqlDbType.NVarChar, 40))
SaveDelete.Parameters("@dotnet.itags.org.ConfirmId").Value = blankSaveDelete.ExecuteNonQuery()
SaveDelete.Parameters("@.ConfirmId").Value = DBNull.Value
set field to dbnull?
how can I set the field to DBNull?
Thanks,
Gary
daClearOrders.Fill(DsClearOrders1)
Dim row As DataRow
For Each row In DsClearOrders1.Inventory.Rows
row("QuantityOrdered") = 0
row("OrderDate") = DBNull (this doesn't work)
Next
daClearOrders.Update(DsClearOrders1)Hi Gary,
Try assigning DBNull.Value instead of DBNull.
Harold
"Gary" <Gary@.nospam.com> wrote in message
news:etjh3kRGEHA.688@.tk2msftngp13.phx.gbl...
> In the following code the line: row("OrderDate") = DBNull is invalid.
But,
> how can I set the field to DBNull?
> Thanks,
> Gary
> daClearOrders.Fill(DsClearOrders1)
> Dim row As DataRow
> For Each row In DsClearOrders1.Inventory.Rows
> row("QuantityOrdered") = 0
> row("OrderDate") = DBNull (this doesn't work)
> Next
> daClearOrders.Update(DsClearOrders1)
set field to dbnull?
how can I set the field to DBNull?
Thanks,
Gary
daClearOrders.Fill(DsClearOrders1)
Dim row As DataRow
For Each row In DsClearOrders1.Inventory.Rows
row("QuantityOrdered") = 0
row("OrderDate") = DBNull (this doesn't work)
Next
daClearOrders.Update(DsClearOrders1)Hi Gary,
Try assigning DBNull.Value instead of DBNull.
Harold
"Gary" <Gary@.nospam.com> wrote in message
news:etjh3kRGEHA.688@.tk2msftngp13.phx.gbl...
> In the following code the line: row("OrderDate") = DBNull is invalid.
But,
> how can I set the field to DBNull?
> Thanks,
> Gary
> daClearOrders.Fill(DsClearOrders1)
> Dim row As DataRow
> For Each row In DsClearOrders1.Inventory.Rows
> row("QuantityOrdered") = 0
> row("OrderDate") = DBNull (this doesn't work)
> Next
> daClearOrders.Update(DsClearOrders1)
Saturday, March 24, 2012
set focus on postback/textchanged
this with the following: Page.RegisterStartupScript("SetFocus", "<script
language=""Jscript"" > document.getElementById(""txtCity"").focus();
</Script>"). This is being called on the textChanged event for textboxes. fo
r
city it goes to state for state it goes to zip, ...
It works, but is this the correct way to do this or should this be a seties
of if then else's in he page load? if so, how can i isolate the textbox that
caused the event?
thanks
kesYou can change the javascript you have below to generate the name of the
control that caused the event:
Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
document.getElementById(" + controlName + ").focus(); </Script>").
in the "Changed" event of the control just set the "controlName" variable to
the required javascript id for the control:
i.e. for the txtCity changed event:
controlName = "txtCity";
I'm assuming that you are calling the Page.RegisterStartupScript() function
in the "Render" event of the page - you'll need to remember that because the
"Render" is called after the "Changed" event and thats what you want, if you
put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
"controlName" variable will not be assigned a value yet.
"Kurt Schroeder" wrote:
> I'm setting focus depenting upon which field has changed value. I'm doing
> this with the following: Page.RegisterStartupScript("SetFocus", "<script
> language=""Jscript"" > document.getElementById(""txtCity"").focus();
> </Script>"). This is being called on the textChanged event for textboxes.
for
> city it goes to state for state it goes to zip, ...
> It works, but is this the correct way to do this or should this be a setie
s
> of if then else's in he page load? if so, how can i isolate the textbox th
at
> caused the event?
> thanks
> kes
Thank you for replying!
i have the function call in each of the respective controls' changed event
:
Example:
Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtbAdr1.TextChanged
If chkShipSame.Checked Then
txtSadr1.Text = txtbAdr1.Text
Page.RegisterStartupScript("SetFocus", "<script
language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
</Script>")
End If
End Sub
In vS.net i could not find the Render event under page, but i'm still
learning this. as well as JavaScript. I see PreRender, but not render.
1. My guess is the funtion calls are not in the right place, but should only
be one function call in the Render event?
2. where can i find Render?
3. the controlname variable is this a simple .net string variable or a
javascript variable?
Thanks
kes
"Jorge L Matos [MCSD.NET]" wrote:
> You can change the javascript you have below to generate the name of the
> control that caused the event:
> Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> document.getElementById(" + controlName + ").focus(); </Script>").
> in the "Changed" event of the control just set the "controlName" variable
to
> the required javascript id for the control:
> i.e. for the txtCity changed event:
> controlName = "txtCity";
> I'm assuming that you are calling the Page.RegisterStartupScript() functio
n
> in the "Render" event of the page - you'll need to remember that because t
he
> "Render" is called after the "Changed" event and thats what you want, if y
ou
> put the Page.RegisterStartupScript() in the Page_Load() by mistake, then t
he
> "controlName" variable will not be assigned a value yet.
> "Kurt Schroeder" wrote:
>
Sorry, I meant the "PreRender" event, not the "Render".
Answers:
1. Yes, but use "PreRender" not "Render"
2. Don't worry about Render
3. The controlName variable is a field of the "Page" class that you create
and all the "Change" events can set it to the javascript ID of the control.
The page events are typically executed in the following order:
a) Init
b) Load
c) Change Events
d) Click Events
e) PreRender
f) Render
REF:
http://msdn.microsoft.com/library/d...onlifecycle.asp
ASP.NET 2.0 will have an enhanced page event life cycle with more events
that you can hook into.
"Kurt Schroeder" wrote:
> Thank you for replying!
> i have the function call in each of the respective controls' changed eve
nt:
> Example:
> Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal
e
> As System.EventArgs) Handles txtbAdr1.TextChanged
> If chkShipSame.Checked Then
> txtSadr1.Text = txtbAdr1.Text
> Page.RegisterStartupScript("SetFocus", "<script
> language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
> </Script>")
> End If
> End Sub
> In vS.net i could not find the Render event under page, but i'm still
> learning this. as well as JavaScript. I see PreRender, but not render.
> 1. My guess is the funtion calls are not in the right place, but should on
ly
> be one function call in the Render event?
> 2. where can i find Render?
> 3. the controlname variable is this a simple .net string variable or a
> javascript variable?
> Thanks
> kes
> "Jorge L Matos [MCSD.NET]" wrote:
>
set focus on postback/textchanged
this with the following: Page.RegisterStartupScript("SetFocus", "<script
language=""Jscript"" > document.getElementById(""txtCity"").focus();
</Script>"). This is being called on the textChanged event for textboxes. for
city it goes to state for state it goes to zip, ...
It works, but is this the correct way to do this or should this be a seties
of if then else's in he page load? if so, how can i isolate the textbox that
caused the event?
thanks
kesYou can change the javascript you have below to generate the name of the
control that caused the event:
Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
document.getElementById(" + controlName + ").focus(); </Script>").
in the "Changed" event of the control just set the "controlName" variable to
the required javascript id for the control:
i.e. for the txtCity changed event:
controlName = "txtCity";
I'm assuming that you are calling the Page.RegisterStartupScript() function
in the "Render" event of the page - you'll need to remember that because the
"Render" is called after the "Changed" event and thats what you want, if you
put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
"controlName" variable will not be assigned a value yet.
"Kurt Schroeder" wrote:
> I'm setting focus depenting upon which field has changed value. I'm doing
> this with the following: Page.RegisterStartupScript("SetFocus", "<script
> language=""Jscript"" > document.getElementById(""txtCity"").focus();
> </Script>"). This is being called on the textChanged event for textboxes. for
> city it goes to state for state it goes to zip, ...
> It works, but is this the correct way to do this or should this be a seties
> of if then else's in he page load? if so, how can i isolate the textbox that
> caused the event?
> thanks
> kes
Thank you for replying!
i have the function call in each of the respective controls' changed event:
Example:
Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles txtbAdr1.TextChanged
If chkShipSame.Checked Then
txtSadr1.Text = txtbAdr1.Text
Page.RegisterStartupScript("SetFocus", "<script
language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
</Script>")
End If
End Sub
In vS.net i could not find the Render event under page, but i'm still
learning this. as well as JavaScript. I see PreRender, but not render.
1. My guess is the funtion calls are not in the right place, but should only
be one function call in the Render event?
2. where can i find Render?
3. the controlname variable is this a simple .net string variable or a
javascript variable?
Thanks
kes
"Jorge L Matos [MCSD.NET]" wrote:
> You can change the javascript you have below to generate the name of the
> control that caused the event:
> Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> document.getElementById(" + controlName + ").focus(); </Script>").
> in the "Changed" event of the control just set the "controlName" variable to
> the required javascript id for the control:
> i.e. for the txtCity changed event:
> controlName = "txtCity";
> I'm assuming that you are calling the Page.RegisterStartupScript() function
> in the "Render" event of the page - you'll need to remember that because the
> "Render" is called after the "Changed" event and thats what you want, if you
> put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
> "controlName" variable will not be assigned a value yet.
> "Kurt Schroeder" wrote:
> > I'm setting focus depenting upon which field has changed value. I'm doing
> > this with the following: Page.RegisterStartupScript("SetFocus", "<script
> > language=""Jscript"" > document.getElementById(""txtCity"").focus();
> > </Script>"). This is being called on the textChanged event for textboxes. for
> > city it goes to state for state it goes to zip, ...
> > It works, but is this the correct way to do this or should this be a seties
> > of if then else's in he page load? if so, how can i isolate the textbox that
> > caused the event?
> > thanks
> > kes
Sorry, I meant the "PreRender" event, not the "Render".
Answers:
1. Yes, but use "PreRender" not "Render"
2. Don't worry about Render
3. The controlName variable is a field of the "Page" class that you create
and all the "Change" events can set it to the javascript ID of the control.
The page events are typically executed in the following order:
a) Init
b) Load
c) Change Events
d) Click Events
e) PreRender
f) Render
REF:
http://msdn.microsoft.com/library/d...onlifecycle.asp
ASP.NET 2.0 will have an enhanced page event life cycle with more events
that you can hook into.
"Kurt Schroeder" wrote:
> Thank you for replying!
> i have the function call in each of the respective controls' changed event:
> Example:
> Private Sub txtbAdr1_TextChanged(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles txtbAdr1.TextChanged
> If chkShipSame.Checked Then
> txtSadr1.Text = txtbAdr1.Text
> Page.RegisterStartupScript("SetFocus", "<script
> language=""Javascript"" > document.getElementById(""txtbadr2"").focus();
> </Script>")
> End If
> End Sub
> In vS.net i could not find the Render event under page, but i'm still
> learning this. as well as JavaScript. I see PreRender, but not render.
> 1. My guess is the funtion calls are not in the right place, but should only
> be one function call in the Render event?
> 2. where can i find Render?
> 3. the controlname variable is this a simple .net string variable or a
> javascript variable?
> Thanks
> kes
> "Jorge L Matos [MCSD.NET]" wrote:
> > You can change the javascript you have below to generate the name of the
> > control that caused the event:
> > Page.RegisterStartupScript("SetFocus", "<script language='Jscript'>
> > document.getElementById(" + controlName + ").focus(); </Script>").
> > in the "Changed" event of the control just set the "controlName" variable to
> > the required javascript id for the control:
> > i.e. for the txtCity changed event:
> > controlName = "txtCity";
> > I'm assuming that you are calling the Page.RegisterStartupScript() function
> > in the "Render" event of the page - you'll need to remember that because the
> > "Render" is called after the "Changed" event and thats what you want, if you
> > put the Page.RegisterStartupScript() in the Page_Load() by mistake, then the
> > "controlName" variable will not be assigned a value yet.
> > "Kurt Schroeder" wrote:
> > > I'm setting focus depenting upon which field has changed value. I'm doing
> > > this with the following: Page.RegisterStartupScript("SetFocus", "<script
> > > language=""Jscript"" > document.getElementById(""txtCity"").focus();
> > > </Script>"). This is being called on the textChanged event for textboxes. for
> > > city it goes to state for state it goes to zip, ...
> > > It works, but is this the correct way to do this or should this be a seties
> > > of if then else's in he page load? if so, how can i isolate the textbox that
> > > caused the event?
> > > > thanks
> > > kes
Set focus on the textbox field in datagrid
when one record was added in the grid, the cursor was lost focus to
somewhere. is it possible to set focus on the textbox for further adding
record in the datagrid
Million thanksCheck out this articles, it might help you.
http://aspalliance.com/aldotnet/exa...autoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com
"Grey" <erickwyum@.i-cable.com> wrote in message
news:#A2nIPNVEHA.712@.TK2MSFTNGP11.phx.gbl...
> I have implemented the datagrid with add function successfully. However,
> when one record was added in the grid, the cursor was lost focus to
> somewhere. is it possible to set focus on the textbox for further adding
> record in the datagrid
> Million thanks
>
Set focus on the textbox field in datagrid
when one record was added in the grid, the cursor was lost focus to
somewhere. is it possible to set focus on the textbox for further adding
record in the datagrid
Million thanksCheck out this articles, it might help you.
http://aspalliance.com/aldotnet/exa...autoscroll.aspx
http://www.dotnetjunkies.com/howto/default.aspx?id=38
--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com
"Grey" <erickwyum@.i-cable.com> wrote in message
news:#A2nIPNVEHA.712@.TK2MSFTNGP11.phx.gbl...
> I have implemented the datagrid with add function successfully. However,
> when one record was added in the grid, the cursor was lost focus to
> somewhere. is it possible to set focus on the textbox for further adding
> record in the datagrid
> Million thanks
Set focus on the field (Form validation in ASP.NET)
I have a problem and really need your help. In my web page ASPX, I have
some text fields to accept data from users. I did form validation like this
:
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute"
runat="server" Width="107px" BorderColor="Transparent"
autoPostback="true"
OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
</td>
<td class="dataTD" style="HEIGHT: 30px" width="100">
<asp:CompareValidator id="CompareValidator1"
runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
ForeColor="LightCoral" ErrorMessage="Please enter a number!"
Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
</td>
In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is valid
or not. If it's valid then I add this value in the TOTAL field. I'd to to
set focus on the next field when this data IS VALID, OR focus on this field
when data IS NOT valid . Can you help me ? Thanks in advanceI suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
all your requests.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"bienwell" <bienwell@.hotmail.com> wrote in message
news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
> Hi,
> I have a problem and really need your help. In my web page ASPX, I have
> some text fields to accept data from users. I did form validation like
> this :
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION:
> absolute" runat="server" Width="107px" BorderColor="Transparent"
> autoPostback="true"
> OnTextChanged="txtFUEL_ISSUED1_TextChanged"></asp:TextBox>
> </td>
> <td class="dataTD" style="HEIGHT: 30px" width="100">
> <asp:CompareValidator id="CompareValidator1"
> runat="server" Width="90px" ControlToValidate="txtFUEL_ISSUED1"
> ForeColor="LightCoral" ErrorMessage="Please enter a number!"
> Operator="DataTypeCheck" Type="Double"></asp:CompareValidator>
> </td>
>
> In the txtFUEL_ISSUED1_TextChanged, I checked if data on this field is
> valid or not. If it's valid then I add this value in the TOTAL field. I'd
> to to set focus on the next field when this data IS VALID, OR focus on
> this field when data IS NOT valid . Can you help me ? Thanks in advance
>
Steve,
I have some questions:
1- There are some versions ASP.NET 2.0 from the www.asp.net web site :
a- .NET Framework 2.0 SDK x86,
b- .NET Framework Version 2.0 Redistributable Package (x86)
c- .NET Framework 2.0 SDK x64
d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
e- .NET Framework 2.0 SDK IA64
f- .NET Framework Version 2.0 Redistributable Package IA64
(64 Bit)
Which one do you suggest me to download ?
2- After downloading, do you think this code will work OR I should
change something ?
Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
Dim strScript As String = "<script language=JavaScript>"
If IsNumeric(txtFUEL_ISSUED1.text) OR
txtFUEL_ISSUED1.text="" Then
Dim aValue as double=0.0
If IsNumeric(txtFUEL_ISSUED1.text) Then
aValue=CDBL(txtFUEL_ISSUED1.Text)
End If
' ADD the value to the TOTAL field
ViewState("FUEL_ISSUED_Total") =
ViewState("FUEL_ISSUED_Total") + aValue - ViewState("FUEL_ISSUED1")
txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("FUEL_ISSUED_Total"),
2, , ,TriState.True)
ViewState("FUEL_ISSUED1") = aValue
strScript = strScript &
"document.form1.txtFUEL_ISSUED2.focus();" 'FOCUS on the next field
Else 'FOCUS on the current field
strScript = strScript &
"document.form1.txtFUEL_ISSUED1.focus();"
End If
strScript = strScript & "<" & "/script>"
If (Not Page.IsStartupScriptRegistered("clientScript")) Then
Page.RegisterStartupScript("clientScript", strScript)
End If
End Sub
========================================
===========
"Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
>I suggest you upgrade to ASP.NET 2.0, which has new features that satisfy
>all your requests.
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://SteveOrr.net
>
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23O5W3po9FHA.476@.TK2MSFTNGP15.phx.gbl...
>
If you have a 32-bit machine ( a standard Intel or AMD )...
If you want the very minimum necessary to run ASP.NET 2.0,
get .NET Framework Version 2.0 Redistributable Package (x86)
If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
get .NET Framework 2.0 SDK x86
If you have a 64-bit machine, your choice may vary depending on the cpu.
The code you posted should run on any of the 5 choices.
Juan T. Llibre
ASP.NET.FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"bienwell" <bienwell@.hotmail.com> wrote in message news:%23KAB7j09FHA.1140@.tk2msftngp13.phx
.gbl...
> Steve,
> I have some questions:
> 1- There are some versions ASP.NET 2.0 from the www.asp.net web site
:
> a- .NET Framework 2.0 SDK x86,
> b- .NET Framework Version 2.0 Redistributable Package (x86)
> c- .NET Framework 2.0 SDK x64
> d- .NET Framework Version 2.0 Redistributable Package x64 (64
Bit)
> e- .NET Framework 2.0 SDK IA64
> f- .NET Framework Version 2.0 Redistributable Package IA64 (
64 Bit)
> Which one do you suggest me to download ?
>
> 2- After downloading, do you think this code will work OR I should cha
nge something ?
> Sub txtFUEL_ISSUED1_TextChanged(sender As Object, e As EventArgs)
> Dim strScript As String = "<script language=JavaScript>"
> If IsNumeric(txtFUEL_ISSUED1.text) OR txtFUEL_ISSUED1.tex
t="" Then
> Dim aValue as double=0.0
> If IsNumeric(txtFUEL_ISSUED1.text) Then
> aValue=CDBL(txtFUEL_ISSUED1.Text)
> End If
> ' ADD the value to the TOTAL field
> ViewState("FUEL_ISSUED_Total") = ViewState("FUEL_ISS
UED_Total") + aValue -
> ViewState("FUEL_ISSUED1")
> txtFUEL_ISSUED_Total.text=FormatNumber(ViewState("F
UEL_ISSUED_Total"), 2, ,
> ,TriState.True)
> ViewState("FUEL_ISSUED1") = aValue
> strScript = strScript & "document.form1.txtFUEL_ISS
UED2.focus();"
> 'FOCUS on the next field
> Else 'FOCUS on the current field
> strScript = strScript & "document.form1.txtFUEL_IS
SUED1.focus();"
> End If
> strScript = strScript & "<" & "/script>"
> If (Not Page.IsStartupScriptRegistered("clientScript")) Then
> Page.RegisterStartupScript("clientScript", strScript)
> End If
> End Sub
> ========================================
===========
> "Steve C. Orr [MVP, MCSD]" <Steve@.Orr.net> wrote in message
> news:%23Tibhzt9FHA.1288@.TK2MSFTNGP09.phx.gbl...
Thank you very much for your advices.
bienwell
==============================
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:eZ$7KP19FHA.904@.TK2MSFTNGP09.phx.gbl...
> If you have a 32-bit machine ( a standard Intel or AMD )...
> If you want the very minimum necessary to run ASP.NET 2.0,
> get .NET Framework Version 2.0 Redistributable Package (x86)
>
> If you want the QuickStart Tutorials, extra tools *and* ASP.NET 2.0,
> get .NET Framework 2.0 SDK x86
> If you have a 64-bit machine, your choice may vary depending on the cpu.
> The code you posted should run on any of the 5 choices.
>
> Juan T. Llibre
> ASP.NET.FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Espaol : http://asp.net.do/foros/
> ======================================
> "bienwell" <bienwell@.hotmail.com> wrote in message
> news:%23KAB7j09FHA.1140@.tk2msftngp13.phx.gbl...
>
>
>
Set Focus to a Text Box Field on a User Web Control
anyone have suggestions on how I should approach this?Something basic like this should work:
Response.Write "<script language = javascript>"& MyTextBox.ClientID &
".focus()</script>"
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Mike Moore" <MikeMoore@.discussions.microsoft.com> wrote in message
news:8EEBC0E1-E38B-4B43-9D8A-889C3E85DF1B@.microsoft.com...
>I would like to set focus to a text box field on a user web control. Does
> anyone have suggestions on how I should approach this?
Set Focus to a Text Box Field on a User Web Control
anyone have suggestions on how I should approach this?Something basic like this should work:
Response.Write "<script language = javascript>"& MyTextBox.ClientID &
".focus()</script>"
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Mike Moore" <MikeMoore@.discussions.microsoft.com> wrote in message
news:8EEBC0E1-E38B-4B43-9D8A-889C3E85DF1B@.microsoft.com...
>I would like to set focus to a text box field on a user web control. Does
> anyone have suggestions on how I should approach this?
Tuesday, March 13, 2012
Set object properties via a loop?
I have a data container object that holds user info, with one public property mapping to each field in my database table.
When retrieving a user's info from my db I'm using a DataReader, and writing code like this:
myDBObj.name = reader["name"];
myDBObj.id = reader["id"];
Etc, etc. This works ok, but I was hoping to use the DataReader's GetName and FieldCount methods to automate setting my property values.
Something like:
for (int i = 0; i <= reader.FieldCount; i++)
{
string fieldName = reader.GetName(i);
usr.[fieldName] = (reader.GetDataTypeName(i))reader[i];
}
The part in bold is throwing me--is there a way to use a variable in determining which property I'm assigning? Is there another way to do what I'm trying?
Thanks!
Aaron
You could try reader[i].ToString()
usr.[fieldName] = reader[i].ToString();
Sample Code:
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand commond = new SqlCommand("SELECT * FROM TEST");
DataSet fillDataSet = new DataSet();
commond.Connection = connection;
commond.CommandType = CommandType.Text;
connection.Open();
SqlDataReader dr;
dr = commond.ExecuteReader();
while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ i.ToString() +":" + dr[i].ToString());
Response.Write("<br>");
}
}
connection.Close();
Obtaining the info via the datareader isn't the problem, the issue is that the object I'm creating (objUserDetail) has properties of varying types (strings, ints, datetimes, etc).
While I could certainly simply write out a long list of property assignments and cast the datareader's info in the correct type each time, I'd much rather figure out a way to do it via a loop.
I figured out how to use a PropertyInfo object to get the names of the properties dynamically at runtime, but now the problem is the datareader is sending all the data back as a string, and I can't find a way to convert/cast it into the format the various properties are expecting.
Normally I would do this:
objUserDetail.UserID = (int)reader["UserID"];
But I need a way to convert the reader's field value dynamically.
Anyone know how?
Can you try this..
(dr[i].GetType()) dr[i].ToString()
while(dr.Read())
{
for(int i=0; i<dr.FieldCount;i++)
{
Response.Write(dr.GetName(i) + ":"+ dr[i].GetType() +":" + dr[i].ToString());
Response.Write("<br>");
}
}
Why don't you use TypeDataSet?
like this:
Dim myDBobjAs New usrDim fieldNameAs String Dim flagsAs BindingFlags = BindingFlags.InstanceOr BindingFlags.Public Or BindingFlags.IgnoreCaseOr BindingFlags.Static Or BindingFlags.FlattenHierarchyDim pAs PropertyInfoDim readerAs System.Data.SqlClient.SqlDataReader = GetTheReader()'populate one entityFor iAs Integer = 0To (reader.FieldCount - 1) fieldname = reader.GetName(i) p =GetType(usr).GetProperty(fieldName, flags) p.SetValue(myDBobj, reader(i),Nothing)Next
Thanks for your help, everyone!
I was able to get it working, and now I'm reconsidering the whole data table class concept, since that's what DataSets are for, right?
aaron
DataSets are basically just collections of DataTables.
NC...