This is a migrated thread and some comments may be shown as answers.

How Attributes RadTextBox TextMode="Password" after postBack

3 Answers 546 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Mohammed asked on 14 Sep 2018, 07:45 PM

How Attributes RadTextBox TextMode="Password" after postBack

I want to help solve this problem

.aspx

<form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:Label ID="Label1" runat="server" Text="Passwoed TextBox"></asp:Label>
        <br />
        <asp:TextBox ID="TextBox1" runat="server" TextMode="Password"></asp:TextBox>
        <br />  <br />
        <asp:Label ID="Label2" runat="server" Text="Passwoed radtextbox"></asp:Label>
        <br />
        <telerik:radtextbox runat="server" ID="radtextbox1" TextMode="Password" Skin="Bootstrap"></telerik:radtextbox>
        <br />  <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>

 

.vb

If Me.IsPostBack Then
 
            radtextbox1.Attributes("value") = radtextbox1.Text.Trim() 'not work         
 
            'TextBox1.Attributes("value") = TextBox1.Text  'this work
            TextBox1.Attributes.Add("value", TextBox1.Text.Trim()) 'this work
 
End If

 

 

3 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 14 Sep 2018, 09:38 PM
Hi Mohammed,

I have just answered your support ticket with this question and I am pasting my answer for anyone else looking at a similar situation.

If I understand correctly, you want to preserve the password input across postbacks. If so, I must begin by noting that this is a browser behavior that is designed to improve security - password fields are cleared if the user has to go back to the login screen. You can reproduce this behavior with the following plain HTML:

<input type="password" name="pwdInput" />
<input type="submit" value="post the page" name="btnSubmit" />

or if you prefer, with ASP controls:

 

<asp:TextBox runat="server" ID="tbPwd" TextMode="Password" />
<asp:Button Text="POST" ID="btn1"  runat="server" />

 

The next important bit is that a password input cannot get its Text from the server. For example, the following will show you the user input while debugging, but it will not be rendered in the browser:

protected void btn1_Click(object sender, EventArgs e)
{
    tbPwd.Text = Request[tbPwd.UniqueID];
}

 

and the same behavior applies to attempting to pre-set it on the initial load

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        tbPwd.Text = "aaa";
    }
 
}

 

The premise for such behavior is that the web application developer should not have access to the password plain text in order to set it for the user, and even if they did - that would be a security breach because the password must not be provided as part of the page.

With this in mind, RadTextBox has the same behavior, and this will not change in order to preserve security.

On the subject why attempting to set attributes may work for a standard input - simply because it bypasses the ASP.NET security mechanism that is tied to the actual control property (Text). The attributes collection can be used to store any value on any attribute and as such is not validated by the framework.

Such hacks would not work on a more complex structure like the RadTextBox.

If you still want to implement such logic, I would suggest adding a RadFormDecorator to the page so it can make the inputs beautiful in the browser without changing their server behavior, instead of using a RadTextBox.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Mohammed
Top achievements
Rank 1
answered on 14 Sep 2018, 10:38 PM

hi Marin Bratanov, 

thank you very much for your reply

[quote]If I understand correctly, you want to preserve the password input across postbacks. If so[/quote]

yes, i want.

Because I use radwizard tools with server-side  

Event (RadWizard1.NextButtonClick)

Example:

If e.NextStep.Index = 2 Then
    If Check_DataRecordID(Value) = True Then
       RadWindowManager1.RadAlert("Here the message")
       Exit Sub
    End If
End If

 

After postback, the password is lost.

Regards,

0
Marin Bratanov
Telerik team
answered on 15 Sep 2018, 12:22 PM
The only suggestion I can offer at the end of my previous post - using a regular password input and using its Attributes collection, as you have found already, and, optionally, adding a RadFormDecorator to make it prettier.
--Marin
Tags
General Discussions
Asked by
Mohammed
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Mohammed
Top achievements
Rank 1
Share this question
or