Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Monday, March 26, 2012

passing variable from Popup

Whats the best way to pass a variable from a popup to the current page
(without a postback on the current page).
I have a form on 'page1' with various text input boxes. One box contains an
image URL. To select the url , the user can click on a browse button to open
a url chooser pop up ('page2'). I want the url that is selected in 'page2'
to be posted back to 'page1' and displayed in the input box, without losing
the values a user has already input in the other textboxes on page1.
I can use the 'previouspage' method, but I don't think this can work with
popups can it? I don't want the user to lose any of the other textboxes if
they have to browse to the url chooser page then return to the page1.
hopefully that all makes sense.
JJyes or I was using:
btn_browse.Attributes.Add("onclick", "java script:window.open('..etc
"Mark Rae" <mark@.markNOSPAMrae.com> wrote in message
news:uJ5DjU0$GHA.3536@.TK2MSFTNGP03.phx.gbl...
> "JJ" <abc@.xyz.com> wrote in message
> news:eEdelQ0$GHA.4680@.TK2MSFTNGP04.phx.gbl...
>
> When you say 'popup', do you mean you're using showModalDialog...?
>
"JJ" <abc@.xyz.com> wrote in message
news:eEdelQ0$GHA.4680@.TK2MSFTNGP04.phx.gbl...

> Whats the best way to pass a variable from a popup to the current page
> (without a postback on the current page).
When you say 'popup', do you mean you're using showModalDialog...?
Write this code, on click event on button leads to close the popup.
/* Start from here*/
String sURL =’’ // selected url
string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage(‘ + sURL
+’); window.opener.document.forms(0).submit();
self.close();</SCRIPT>";
Page.RegisterClientScriptBlock("ClosePopup", strScript);
/* Ends here*/
Declare the this javascript function SendBackURLTOMainPage(val) in the main
page (aspx)
hdnURL is the hidden variable which store the selected URL from the popup
page.
function SendBackURLTOMainPage (val)
{
document.getElementById("hdnURL").innerText = val;
}
all the best,
Lokesh
"JJ" wrote:

> Whats the best way to pass a variable from a popup to the current page
> (without a postback on the current page).
> I have a form on 'page1' with various text input boxes. One box contains a
n
> image URL. To select the url , the user can click on a browse button to op
en
> a url chooser pop up ('page2'). I want the url that is selected in 'page2'
> to be posted back to 'page1' and displayed in the input box, without losin
g
> the values a user has already input in the other textboxes on page1.
> I can use the 'previouspage' method, but I don't think this can work with
> popups can it? I don't want the user to lose any of the other textboxes if
> they have to browse to the url chooser page then return to the page1.
>
> hopefully that all makes sense.
> JJ
>
>
Thanks Lokesh. But is there any way of doing this in ASP.net rather than
javascript?
"Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
> Write this code, on click event on button leads to close the popup.
> /* Start from here*/
> String sURL ='' // selected url
> string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage(' + sURL
> +'); window.opener.document.forms(0).submit();
> self.close();</SCRIPT>";
> Page.RegisterClientScriptBlock("ClosePopup", strScript);
> /* Ends here*/
>
> Declare the this javascript function SendBackURLTOMainPage(val) in the
> main
> page (aspx)
> hdnURL is the hidden variable which store the selected URL from the popup
> page.
> function SendBackURLTOMainPage (val)
> {
> document.getElementById("hdnURL").innerText = val;
> }
> all the best,
> Lokesh
> "JJ" wrote:
>
Also,
If I wanted to pass the variable into different textboxes, (depending on
which 'browse' button was clicked) is there a way of doing this?
JJ
"JJ" <abc@.xyz.com> wrote in message
news:e0Vl2y0$GHA.1464@.TK2MSFTNGP02.phx.gbl...
> Thanks Lokesh. But is there any way of doing this in ASP.net rather than
> javascript?
> "Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
> news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
>
"JJ" <abc@.xyz.com> wrote in message
news:e0Vl2y0$GHA.1464@.TK2MSFTNGP02.phx.gbl...

> Thanks Lokesh. But is there any way of doing this in ASP.net rather than
> javascript?
No. ASP.NET is server-side, and can't obviously open windows client-side -
you need JavaScript for that.
Ok I've been trying to do this but without success:
I have a button on my urlChooser page:
protected void Button1_OnClick(object sender, System.EventArgs e)
{
String sURL = this.ImageURL_txtbox.Text; // selected url
string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage('" + sURL +
"'); window.opener.document.forms(0).submit();self.close();</SCRIPT>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"ClosePopup",
strScript);
}
and the javascript function in my main page is:
<script type="text/javascript">
function SendBackURLTOMainPage (val)
{
document.getElementById('TextBox1').value=val;
}
</script>
However, the urlChooser page comes up with an error when I click the button,
and the urlChooser window doesn't close. The error says there's an invald
character in this line:
<SCRIPT>window.opener.SendBackURLTOMainPage('/WebSite1/Uploads/XPS1/admin2/C
ivic_photo.gif');
window.opener.document.forms(0).submit();self.close();</SCRIPT>
(forgive me but I'm not too familiar with javascript)
JJ
"Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
> Write this code, on click event on button leads to close the popup.
> /* Start from here*/
> String sURL ='' // selected url
> string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage(' + sURL
> +'); window.opener.document.forms(0).submit();
> self.close();</SCRIPT>";
> Page.RegisterClientScriptBlock("ClosePopup", strScript);
> /* Ends here*/
>
> Declare the this javascript function SendBackURLTOMainPage(val) in the
> main
> page (aspx)
> hdnURL is the hidden variable which store the selected URL from the popup
> page.
> function SendBackURLTOMainPage (val)
> {
> document.getElementById("hdnURL").innerText = val;
> }
> all the best,
> Lokesh
> "JJ" wrote:
>
Found the problem, the single quotes need to be double quotes. Sorry. Still
learning...
"JJ" <abc@.xyz.com> wrote in message
news:ObG8i62$GHA.2328@.TK2MSFTNGP02.phx.gbl...
> Ok I've been trying to do this but without success:
> I have a button on my urlChooser page:
> protected void Button1_OnClick(object sender, System.EventArgs e)
> {
> String sURL = this.ImageURL_txtbox.Text; // selected url
> string strScript = "<SCRIPT>window.opener.SendBackURLTOMainPage('" + sURL
> + "'); window.opener.document.forms(0).submit();self.close();</SCRIPT>";
> Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"ClosePopup",
> strScript);
> }
> and the javascript function in my main page is:
> <script type="text/javascript">
> function SendBackURLTOMainPage (val)
> {
> document.getElementById('TextBox1').value=val;
> }
> </script>
>
> However, the urlChooser page comes up with an error when I click the
> button, and the urlChooser window doesn't close. The error says there's an
> invald character in this line:
> <SCRIPT>window.opener.SendBackURLTOMainPage('/WebSite1/Uploads/XPS1/admin2
/Civic_photo.gif');
> window.opener.document.forms(0).submit();self.close();</SCRIPT>
>
> (forgive me but I'm not too familiar with javascript)
>
> JJ
>
>
>
>
>
> "Lokesh Reddy" <Lokesh Reddy@.discussions.microsoft.com> wrote in message
> news:662ECFA3-6669-4DC7-97CF-334B00111516@.microsoft.com...
>

Friday, March 16, 2012

Password Field

Have a textbox that's in Password mode on a user creation page. Have
several dropdowns that cause a PostBack out of necessity on this page. I
cannot separate them. When one of these dropdowns changes, the textbox's
value is lost. How do I prevent this?

Thanksthe best way would be to remember it from the original postback, so it only
passes over the network once. otherwise you can use a hack, and set the
control's "value" attribute.

-- bruce (sqlwork.com)

"James" <minorkeys@.gmail.com> wrote in message
news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
> Have a textbox that's in Password mode on a user creation page. Have
> several dropdowns that cause a PostBack out of necessity on this page. I
> cannot separate them. When one of these dropdowns changes, the textbox's
> value is lost. How do I prevent this?
> Thanks
Can I? I've tried setting it in my Page Load event and it doesn't seem to
persist. I've also tried using a client side control with runat=server.
None of the above seem to want to let me set the value.

"Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
> the best way would be to remember it from the original postback, so it
> only passes over the network once. otherwise you can use a hack, and set
> the control's "value" attribute.
> -- bruce (sqlwork.com)
>
> "James" <minorkeys@.gmail.com> wrote in message
> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>> Have a textbox that's in Password mode on a user creation page. Have
>> several dropdowns that cause a PostBack out of necessity on this page. I
>> cannot separate them. When one of these dropdowns changes, the textbox's
>> value is lost. How do I prevent this?
>>
>> Thanks
>>
You have to do it on the client side using javascript.

Losing the value of a password field is pretty standard. If the password
field is the last one on your page, it should in theory be the last field a
user fills in, so it geting emptied shouldn't really happen.

"James" <minorkeys@.gmail.com> wrote in message
news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
> Can I? I've tried setting it in my Page Load event and it doesn't seem to
> persist. I've also tried using a client side control with runat=server.
> None of the above seem to want to let me set the value.
> "Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
> news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
>> the best way would be to remember it from the original postback, so it
>> only passes over the network once. otherwise you can use a hack, and set
>> the control's "value" attribute.
>>
>> -- bruce (sqlwork.com)
>>
>>
>>
>> "James" <minorkeys@.gmail.com> wrote in message
>> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>>> Have a textbox that's in Password mode on a user creation page. Have
>>> several dropdowns that cause a PostBack out of necessity on this page.
>>> I cannot separate them. When one of these dropdowns changes, the
>>> textbox's value is lost. How do I prevent this?
>>>
>>> Thanks
>>>
>>
>>
JavaScript doesn't seem to work either. It isn't the last field they will
enter, and even if it were, there's no way they'd go for that =/.

"Marina" <someone@.nospam.com> wrote in message
news:OTk4sojEGHA.524@.TK2MSFTNGP09.phx.gbl...
> You have to do it on the client side using javascript.
> Losing the value of a password field is pretty standard. If the password
> field is the last one on your page, it should in theory be the last field
> a user fills in, so it geting emptied shouldn't really happen.
> "James" <minorkeys@.gmail.com> wrote in message
> news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
>> Can I? I've tried setting it in my Page Load event and it doesn't seem
>> to persist. I've also tried using a client side control with
>> runat=server. None of the above seem to want to let me set the value.
>>
>> "Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
>> news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
>>> the best way would be to remember it from the original postback, so it
>>> only passes over the network once. otherwise you can use a hack, and set
>>> the control's "value" attribute.
>>>
>>> -- bruce (sqlwork.com)
>>>
>>>
>>>
>>> "James" <minorkeys@.gmail.com> wrote in message
>>> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>>>> Have a textbox that's in Password mode on a user creation page. Have
>>>> several dropdowns that cause a PostBack out of necessity on this page.
>>>> I cannot separate them. When one of these dropdowns changes, the
>>>> textbox's value is lost. How do I prevent this?
>>>>
>>>> Thanks
>>>>
>>>
>>>
>>
>>
I know for a fact that if you set the value on an input control that is a
password type in javascript, that it does get set correctly. Maybe you need
to post your code then.

I bet your users will like the fact that their password is being sent in
clear text in the browser even less then having to retype their password,
since that is the only way to preserve it in between posts. I would
recommend either accepting that passwords will be blank between posts (this
happens pretty much in every other registration system), re-organize your
registration in such a way that the password gets its own page and it is the
last page in the registration process, or code using the javascript solution
and have the password be sent in clear text - which should be the last
resort.

"James" <minorkeys@.gmail.com> wrote in message
news:uzLRXrjEGHA.1032@.TK2MSFTNGP11.phx.gbl...
> JavaScript doesn't seem to work either. It isn't the last field they will
> enter, and even if it were, there's no way they'd go for that =/.
> "Marina" <someone@.nospam.com> wrote in message
> news:OTk4sojEGHA.524@.TK2MSFTNGP09.phx.gbl...
>> You have to do it on the client side using javascript.
>>
>> Losing the value of a password field is pretty standard. If the password
>> field is the last one on your page, it should in theory be the last field
>> a user fills in, so it geting emptied shouldn't really happen.
>>
>> "James" <minorkeys@.gmail.com> wrote in message
>> news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
>>> Can I? I've tried setting it in my Page Load event and it doesn't seem
>>> to persist. I've also tried using a client side control with
>>> runat=server. None of the above seem to want to let me set the value.
>>>
>>> "Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
>>> news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
>>>> the best way would be to remember it from the original postback, so it
>>>> only passes over the network once. otherwise you can use a hack, and
>>>> set the control's "value" attribute.
>>>>
>>>> -- bruce (sqlwork.com)
>>>>
>>>>
>>>>
>>>> "James" <minorkeys@.gmail.com> wrote in message
>>>> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>>>>> Have a textbox that's in Password mode on a user creation page. Have
>>>>> several dropdowns that cause a PostBack out of necessity on this page.
>>>>> I cannot separate them. When one of these dropdowns changes, the
>>>>> textbox's value is lost. How do I prevent this?
>>>>>
>>>>> Thanks
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
Thanks for the help, this seems to work on Postback:

tbPassword.Attributes("value") = tbPassword.Text

"Marina" <someone@.nospam.com> wrote in message
news:eKbInxjEGHA.216@.TK2MSFTNGP15.phx.gbl...
>I know for a fact that if you set the value on an input control that is a
>password type in javascript, that it does get set correctly. Maybe you
>need to post your code then.
> I bet your users will like the fact that their password is being sent in
> clear text in the browser even less then having to retype their password,
> since that is the only way to preserve it in between posts. I would
> recommend either accepting that passwords will be blank between posts
> (this happens pretty much in every other registration system), re-organize
> your registration in such a way that the password gets its own page and it
> is the last page in the registration process, or code using the javascript
> solution and have the password be sent in clear text - which should be the
> last resort.
> "James" <minorkeys@.gmail.com> wrote in message
> news:uzLRXrjEGHA.1032@.TK2MSFTNGP11.phx.gbl...
>> JavaScript doesn't seem to work either. It isn't the last field they
>> will enter, and even if it were, there's no way they'd go for that =/.
>>
>> "Marina" <someone@.nospam.com> wrote in message
>> news:OTk4sojEGHA.524@.TK2MSFTNGP09.phx.gbl...
>>> You have to do it on the client side using javascript.
>>>
>>> Losing the value of a password field is pretty standard. If the
>>> password field is the last one on your page, it should in theory be the
>>> last field a user fills in, so it geting emptied shouldn't really
>>> happen.
>>>
>>> "James" <minorkeys@.gmail.com> wrote in message
>>> news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
>>>> Can I? I've tried setting it in my Page Load event and it doesn't seem
>>>> to persist. I've also tried using a client side control with
>>>> runat=server. None of the above seem to want to let me set the value.
>>>>
>>>> "Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
>>>> news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
>>>>> the best way would be to remember it from the original postback, so it
>>>>> only passes over the network once. otherwise you can use a hack, and
>>>>> set the control's "value" attribute.
>>>>>
>>>>> -- bruce (sqlwork.com)
>>>>>
>>>>>
>>>>>
>>>>> "James" <minorkeys@.gmail.com> wrote in message
>>>>> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>>>>>> Have a textbox that's in Password mode on a user creation page. Have
>>>>>> several dropdowns that cause a PostBack out of necessity on this
>>>>>> page. I cannot separate them. When one of these dropdowns changes,
>>>>>> the textbox's value is lost. How do I prevent this?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>

Password Field

Have a textbox that's in Password mode on a user creation page. Have
several dropdowns that cause a PostBack out of necessity on this page. I
cannot separate them. When one of these dropdowns changes, the textbox's
value is lost. How do I prevent this?
Thanksthe best way would be to remember it from the original postback, so it only
passes over the network once. otherwise you can use a hack, and set the
control's "value" attribute.
-- bruce (sqlwork.com)
"James" <minorkeys@.gmail.com> wrote in message
news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
> Have a textbox that's in Password mode on a user creation page. Have
> several dropdowns that cause a PostBack out of necessity on this page. I
> cannot separate them. When one of these dropdowns changes, the textbox's
> value is lost. How do I prevent this?
> Thanks
>
Can I? I've tried setting it in my Page Load event and it doesn't seem to
persist. I've also tried using a client side control with runat=server.
None of the above seem to want to let me set the value.
"Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
> the best way would be to remember it from the original postback, so it
> only passes over the network once. otherwise you can use a hack, and set
> the control's "value" attribute.
> -- bruce (sqlwork.com)
>
> "James" <minorkeys@.gmail.com> wrote in message
> news:ODtJUcjEGHA.516@.TK2MSFTNGP15.phx.gbl...
>
You have to do it on the client side using javascript.
Losing the value of a password field is pretty standard. If the password
field is the last one on your page, it should in theory be the last field a
user fills in, so it geting emptied shouldn't really happen.
"James" <minorkeys@.gmail.com> wrote in message
news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
> Can I? I've tried setting it in my Page Load event and it doesn't seem to
> persist. I've also tried using a client side control with runat=server.
> None of the above seem to want to let me set the value.
> "Bruce Barker" <brubar_nospamplease_@.safeco.com> wrote in message
> news:umI$3ijEGHA.2012@.TK2MSFTNGP14.phx.gbl...
>
JavaScript doesn't seem to work either. It isn't the last field they will
enter, and even if it were, there's no way they'd go for that =/.
"Marina" <someone@.nospam.com> wrote in message
news:OTk4sojEGHA.524@.TK2MSFTNGP09.phx.gbl...
> You have to do it on the client side using javascript.
> Losing the value of a password field is pretty standard. If the password
> field is the last one on your page, it should in theory be the last field
> a user fills in, so it geting emptied shouldn't really happen.
> "James" <minorkeys@.gmail.com> wrote in message
> news:%235n36mjEGHA.3200@.tk2msftngp13.phx.gbl...
>
I know for a fact that if you set the value on an input control that is a
password type in javascript, that it does get set correctly. Maybe you need
to post your code then.
I bet your users will like the fact that their password is being sent in
clear text in the browser even less then having to retype their password,
since that is the only way to preserve it in between posts. I would
recommend either accepting that passwords will be blank between posts (this
happens pretty much in every other registration system), re-organize your
registration in such a way that the password gets its own page and it is the
last page in the registration process, or code using the javascript solution
and have the password be sent in clear text - which should be the last
resort.
"James" <minorkeys@.gmail.com> wrote in message
news:uzLRXrjEGHA.1032@.TK2MSFTNGP11.phx.gbl...
> JavaScript doesn't seem to work either. It isn't the last field they will
> enter, and even if it were, there's no way they'd go for that =/.
> "Marina" <someone@.nospam.com> wrote in message
> news:OTk4sojEGHA.524@.TK2MSFTNGP09.phx.gbl...
>
Thanks for the help, this seems to work on Postback:
tbPassword.Attributes("value") = tbPassword.Text
"Marina" <someone@.nospam.com> wrote in message
news:eKbInxjEGHA.216@.TK2MSFTNGP15.phx.gbl...
>I know for a fact that if you set the value on an input control that is a
>password type in javascript, that it does get set correctly. Maybe you
>need to post your code then.
> I bet your users will like the fact that their password is being sent in
> clear text in the browser even less then having to retype their password,
> since that is the only way to preserve it in between posts. I would
> recommend either accepting that passwords will be blank between posts
> (this happens pretty much in every other registration system), re-organize
> your registration in such a way that the password gets its own page and it
> is the last page in the registration process, or code using the javascript
> solution and have the password be sent in clear text - which should be the
> last resort.
> "James" <minorkeys@.gmail.com> wrote in message
> news:uzLRXrjEGHA.1032@.TK2MSFTNGP11.phx.gbl...
>

Password field is cleared after postback

Hello,
I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a postback,
in order to fill the second dropdown according to the value selected in the
first dropdown.
The problem is that the password field which has been filled up before is
cleared after postback.
I know this is for security, but is there a way to keep the password'
Thank youdana lees wrote:

> Hello,
> I am developing a C# asp.net application.
> I have a webform which contains 2 dropdowns and a textbox with
> type="password".
> On "SelectedIndexChanged" event of the first dropdown, there is a
> postback, in order to fill the second dropdown according to the value
> selected in the first dropdown.
> The problem is that the password field which has been filled up before is
> cleared after postback.
> I know this is for security, but is there a way to keep the password'
> Thank you
Yes, you can add a "value" attribute to the password textbox on postback:
txtPassword.Attributes.Add("value", txtPassword.Text)
Ben
I have tried that and it didn't work. The field stayed empty...
"Ben Amada" <ben@.REpoMOweVErpick.com> wrote in message
news:OaFdNkA8FHA.3804@.TK2MSFTNGP12.phx.gbl...
> dana lees wrote:
>
is
> Yes, you can add a "value" attribute to the password textbox on postback:
> txtPassword.Attributes.Add("value", txtPassword.Text)
> Ben
>
dana lees wrote:

> I have tried that and it didn't work. The field stayed empty...
Hmm... not sure why that doesn't work. Are you using .NET v2.0? I've done
it in v1.1 without any problems.
Another option is to manually set the value of the password field via
JavaScript. There are several ways to do this.
One way is to create a hidden input field. On postback, put the password in
the hidden input field (i.e. txtHiddenPwd.Value = txtPwd.Text). Then with a
startup script or via the body tag's onload attribute, set the value of the
password textbox to the value of the hidden input field.
Ben
I am using version 1.1.
On debug, I see that i do have the value of the password after postback, i
just can't set the textbox with that value.
I have tried also java script:
document.all.txtPassword.InnerText = "some text";
and this doesn't work as well...
I don't need to use a hidden textbox becuase i do have the value after
postback, i just can't set the textbox's value to that value...
"Ben Amada" <ben@.REpoMOweVErpick.com> wrote in message
news:u2Kz1wA8FHA.4076@.tk2msftngp13.phx.gbl...
> dana lees wrote:
>
> Hmm... not sure why that doesn't work. Are you using .NET v2.0? I've
done
> it in v1.1 without any problems.
> Another option is to manually set the value of the password field via
> JavaScript. There are several ways to do this.
> One way is to create a hidden input field. On postback, put the password
in
> the hidden input field (i.e. txtHiddenPwd.Value = txtPwd.Text). Then with
a
> startup script or via the body tag's onload attribute, set the value of
the
> password textbox to the value of the hidden input field.
> Ben
>
dana lees wrote:

> I am using version 1.1.
> On debug, I see that i do have the value of the password after postback, i
> just can't set the textbox with that value.
> I have tried also java script:
> document.all.txtPassword.InnerText = "some text";
> and this doesn't work as well...
> I don't need to use a hidden textbox becuase i do have the value after
> postback, i just can't set the textbox's value to that value...
Server-side you can't set the textbox's value to the password. However,
with JavaScript (client-side) you should be able to set the value of the
textbox with or without a hidden input field. Without a hidden input field,
you could simply add a runat="server" attribute to the <body> tag, then on
the server-side during a postback, you can add an "onload" attribute to the
body tag specifying the password value. Like this:
===== HTML =====
<body id="myBody" runat="server">
===== Code-Behind =====
myBody.Attributes.Add("onload", _
"document.getElementById('txtPassword').value = '" & _
txtPassword.Text & "'")
(the C# syntax should be similar)
Also, in the code-behind, if Visual Studio doesn't recognize the "myBody"
control (which happens sometimes), you'll probably have to manually add the
control declaration to the code-behind:
Dim myBody As HtmlControls.HtmlGenericControl
... or instead of adding an "onload" attribute to the body tag, you could
use the RegisterStartupScript method to set the password textbox value.
Ben
dana lees wrote:

> I have tried also java script:
> document.all.txtPassword.InnerText = "some text";
> and this doesn't work as well...
By the way, what do you mean that it "doesn't work as well"? How about :
document.getElementById('txtPassword').value = "some text";
Ben
It worked, when using
document.getElementById('txtPassword').value = "some text";
Thank you very much :-)
"Ben Amada" <ben@.REpoMOweVErpick.com> wrote in message
news:%23G3ExQB8FHA.3200@.TK2MSFTNGP11.phx.gbl...
> dana lees wrote:
>
> By the way, what do you mean that it "doesn't work as well"? How about :
> document.getElementById('txtPassword').value = "some text";
> Ben
>
Dana,
As Ben suggested you can use assword.Attributes.Add("value",
txtPassword.Text) to set the password .But instead of txtPassword.Text you
should retrieve password text using
txtPassword.Attributes["value"].ToString().
"dana lees" wrote:

> I have tried that and it didn't work. The field stayed empty...
> "Ben Amada" <ben@.REpoMOweVErpick.com> wrote in message
> news:OaFdNkA8FHA.3804@.TK2MSFTNGP12.phx.gbl...
> is
>
>
Check out:
http://groups.google.com/group/micr...de23fa30643fa4e
and
http://groups.google.com/group/micr...f9f3be06c4f0396
(watch for link brakage). Basically, you need to reset the value manually
via Password.Attributes.Add("value", Password.Text) or something
karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"dana lees" <danal@.idc.ac.il> wrote in message
news:%23jWQj9$7FHA.4036@.TK2MSFTNGP11.phx.gbl...
> Hello,
> I am developing a C# asp.net application.
> I have a webform which contains 2 dropdowns and a textbox with
> type="password".
> On "SelectedIndexChanged" event of the first dropdown, there is a
> postback,
> in order to fill the second dropdown according to the value selected in
> the
> first dropdown.
> The problem is that the password field which has been filled up before is
> cleared after postback.
> I know this is for security, but is there a way to keep the password'
> Thank you
>

Password Fields Lose Value During PostBack

I have a form, and when the form does a PostBack (I have several areas on
the form where the form changes if the user selects a different
RadioButton), the Password field is cleared, even though I have
EnableViewState set to True. None of the other TextBoxes lose their value. I
also tried using Session variables to store the value between postbacks, but
I must be doing this in the wrong event, because it does not seem to be
having an effect. What can I do to prevent the Password field from losing
it's value? Thanks.
--
Nathan Sokalski
njsokalski@dotnet.itags.org.hotmail.com
http://www.nathansokalski.com/This is a security feature. So the password isn't sent down to the browser
in clear text.

The ViewState is just an encrypted version of what was last sent down, so
that next time there is a post to the server, it can all be sent back up as
one thing. It can then be used on the server, to see if a field's value
changed, etc.

The browser does not care about ViewState, and does not use it to populate
its controls.

There is no way to override the behavior. The only way you can do this, is
to do it in javascript, but that would most likely mean sending the password
down in clear text, where anyone who knows how to do View -> Source can look
at it.

"Nathan Sokalski" <njsokalski@.hotmail.com> wrote in message
news:%23mvV7GDeFHA.3328@.TK2MSFTNGP09.phx.gbl...
>I have a form, and when the form does a PostBack (I have several areas on
>the form where the form changes if the user selects a different
>RadioButton), the Password field is cleared, even though I have
>EnableViewState set to True. None of the other TextBoxes lose their value.
>I also tried using Session variables to store the value between postbacks,
>but I must be doing this in the wrong event, because it does not seem to be
>having an effect. What can I do to prevent the Password field from losing
>it's value? Thanks.
> --
> Nathan Sokalski
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/
This is the default behavior. It minimizes passwords being transmitted
around the internet any more than they have to be. It's a security
precaution.

There is a workaround if you're determined. You can set the password text
via client side script.
Here's the simplest example I've seen:

MyPWTextBox.Attributes.Add("value", strPassword)

This server side code outputs the needed client side code to fill in the
password. For reasons mentioned earlier, it's preferable to avoid
transmitting the password around like this when possible.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Nathan Sokalski" <njsokalski@.hotmail.com> wrote in message
news:%23mvV7GDeFHA.3328@.TK2MSFTNGP09.phx.gbl...
>I have a form, and when the form does a PostBack (I have several areas on
>the form where the form changes if the user selects a different
>RadioButton), the Password field is cleared, even though I have
>EnableViewState set to True. None of the other TextBoxes lose their value.
>I also tried using Session variables to store the value between postbacks,
>but I must be doing this in the wrong event, because it does not seem to be
>having an effect. What can I do to prevent the Password field from losing
>it's value? Thanks.
> --
> Nathan Sokalski
> njsokalski@.hotmail.com
> http://www.nathansokalski.com/