-2

I have used a login-template for the page in .net application. How can I get the texts from the input text fields of the template and store it in a string variable?

<form id="form1" runat="server" role="form" method="post" class="login-form">
                                    <div class="form-group" runat="server">
                                        <label class="sr-only" for="form-username">Username</label>
                                        <input type="text" name="form-username" placeholder="Username..." class="form-username form-control" id="form_username" runat="server"/>
                                    </div>
                                    <div class="form-group" runat="server">
                                        <label class="sr-only" for="form-password">Password</label>
                                        <input type="password" name="form-password" placeholder="Password..." class="form-password form-control" id="form_password" runat="server"/>
                                    </div>
                                    <button type="submit" class="btn" onclick="btn_login_Click" runat="server">LOGIN</button>
                            </form>

4 Answers4

0

To get the Text in a TextBox you can simply do this:

private void AnyMethod()
{
    string textValue = this.MyTextBox.Text;
}
Felix D.
  • 4,811
  • 8
  • 38
  • 72
Jamez Fatout
  • 402
  • 4
  • 13
0

You can access the raw post data with:

string exampleInput = Request.Form["<inputElementName>"];

If your input element is having the attribute 'runat="server"' you should be able to access it with

string exampleInput = <inputElementName>.Value;

If this does not work, you would need to show us a little bit more of your code/page.

Sample form:

<form id="login" runat="server">
 <asp:TextBox ID="tbInput1" runat="server" 
                            Width="75px" 
                            TabIndex="1">
 </asp:TextBox>
 <asp:Button ID="btSubmit" runat="server" Text="Submit" />
</form>

Access with

tbInput1.Text
dsdel
  • 1,042
  • 1
  • 8
  • 11
0

I guess ,if runat=server is there then it should directly get value using :

form_username.value.Tostring().

Mrunalini
  • 256
  • 1
  • 6
  • Yes. I i have written same piece of code to get the value but I think the problem might be in the OnClick event of the button. How do I make a onClick method for a template button? – TesseractT.Shailab Mar 28 '18 at 14:14
  • Try using :.For more reference please visit this link : https://stackoverflow.com/questions/3167246/asp-net-html-html-buttons-onclick-property-inside-asp-net-cs – Mrunalini Mar 28 '18 at 14:32
0

After doing little research on above issue got to know that ,

we can't access the login control properties directly .

if we want to access name then we have to use : User.Identity.Name

try doing this ! it might help you .

For further reference please visit below link : https://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirecttologinpage.aspx

Mrunalini
  • 256
  • 1
  • 6