How can I access the textbox value - c#

<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
runat="server">
<ItemTemplate>
<a href="#" data-inline="true" data-role="button"
data-icon="star" data-iconpos="right">
<input type="text" id="txtTry" style="width: 20%" runat="server"
value="" data-mini="true"
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</a>
</ItemTemplate>
</asp:DataList>
how can I access the value of the text box of each button in the CS. How can I access it.This is not tough but I didn't use it yet.

You need to change HTML controls <input>
to the ASP.NET controls, for example:
<asp:TextBox ID="txtTry" runat="server"></asp:TextBox>
Then later in your .cs file you can change the value of the textbox:
...
txtTry.Text = "foo";
...

yes change the html to Asp.net text box. Then you can get via method mentioned by oleksii
Even with input html text try the below sample It should normally be done with
Request.Form["elementName"]
For example, if you have
<input type="text" name="try" /> then you can use Request.Form["try"] to access its value.

Related

How to hide Literal in Codebehind within a ListView

I currently have a panel within a listview, displaying a bunch of literals. There is a column I need to hide in the codebehind of the page. How would I go about this? The panel that contains these literal fields has UpdateMode on always.
<div class="col-md-2 col-sm-3 col-sm-offset-0 col-xs-4 col-xs-offset-0 col-md-offset-0 text-truncate ">
<p class="key">
<asp:Literal ID="Literal4" runat="server" Text='' />
</p>
<p class="text-truncate">
<asp:Literal ID="Literal7" runat="server" Text=' <%# Eval("Status") %>' />
</p>
</div>
If you are aiming to hide them from the view, you can use the code behind as displayed in this answer
Literal4.Visible = false;

Need to add 'for' attibutes to labels inside a ListView control of an ASP.NET page

I have something like this
<asp:ListView ID="lvOptions" runat="server"">
<LayoutTemplate>
<p>Select an option<span>*</span></p>
<div class="row">
<asp:Literal runat="server" ID="groupPlaceHolder"></asp:Literal>
</div>
<div class="row">
<div class="w100">
<label>
Other types:</label>
<asp:DropDownList ID="ddlOtherTypes" runat="server" DataTextField="Description" DataValueField="Id"
AutoPostBack="true" Enabled="false"
</asp:DropDownList>
</div>
</div>
</LayoutTemplate>
<GroupTemplate>
<asp:Literal runat="server" ID="itemPlaceHolder"></asp:Literal>
</GroupTemplate>
<ItemTemplate>
<span class="wrap-w50">
<asp:RadioButton runat="server" ID="rdbOption" AutoPostBack="true" />
<label>
<%# Eval("Description") %></label>
</span>
</ItemTemplate>
</asp:ListView>
And I got here two labels, one fot the Other types DropDownList, and another for each RadioButton.
For this labels, I need to add a "for" attribute, and I need the clientID but, if I try to write the attibute like:
for="<%= ddlOtherTypes.ClientID %>"
for="<%= rdbOption.ClientID %>"
I got the error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Any suggestions please?
Thank you in advance.

How do I go about accessing the text input from a textbox within a content template in my C# code behind file?

I have used a few variations of accessing the text from StreetNbrtxt including
1) Directly: Profile.StreetNbr = StreetNbrtxt.Text; (Didn't work)
2) Using FindControl: Profile.StreetNbr = ((TextBox)RegisterUserWizardStep.FindControl("StreetNbrtxt")).Text; ('Not a instantiated class' Error message)
Further, I have not been able to see the values that I added in the text boxes that were added to the pre-coded files that were in the Account folder in Visual Studio Express 2012.
The code I have from the Register.aspx is as follows:
<asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatedUser="RegisterUser_CreatedUser" ActiveStepIndex="0">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
<asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="RegisterUserWizardStep">
<ContentTemplate>
<p class="message-info">
Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
</p>
<p class="validation-summary-errors">
<asp:Literal runat="server" ID="ErrorMessage" />
</p>
<fieldset>
<legend>Registration Form</legend>
<ol>
<p>
<asp:Label runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</p>
:
:
:
:
:
<p>
<asp:Label ID="StreetNumberlbl" runat="server" AssociatedControlID="StreetNbrtxt">Street Number:</asp:Label>
<asp:TextBox ID="StreetNbrtxt" runat="server" CssClass="style11"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="StreetNbrtxt"
CssClass="failureNotification" ErrorMessage="A street address number is required" ToolTip="Please insert your home address number"
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
</ol>
<asp:Button runat="server" CommandName="MoveNext" Text="Register" />
</fieldset>
</ContentTemplate>
Any Idea of how I should access the Street Number from the user input textbox?
CreateUserWizard Control is based on Wizard control, which has steps. So you need to find the control inside the step. In your case, it is in the first step. You can access the control like this.
TextBox StreetNbrtxt =
(TextBox)RegisterUser.WizardSteps[0].
FindControl("CreateUserStepContainer").FindControl("StreetNbrtxt");
You can see how it works. I hope this works for you too, as it is working for me for a long time. Thanks!
Edit: Here is the link for more reading about wizard control at official website.

<asp:PlaceHolder> is not showing on iphone

I have a code in my master page that I used placeholder to show and hide 2 different parts.It is completely works fine in all the Browsers, but it is not working on Iphone Even it is working on Android.
this is my code:
<div class="actions">
<asp:PlaceHolder ID="phLogout" runat="server">
<input TYPE="button" VALUE="Log Out" class="Button Orange" onclick="window.location.href = 'Logout.aspx'">
</asp:PlaceHolder>
<asp:PlaceHolder ID="phLogin" runat="server">
<p class="Title">Current users sign in:</p>
<asp:TextBox runat="server" ID="username" holder="Username"></asp:TextBox>
<asp:TextBox runat="server" ID="password" holder="Password" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Log In" class="Button Orange" OnClick="btn_login_Click" ></asp:Button>
<p class="Forgot">Forgot password?</p>
</asp:PlaceHolder>
</div>
I just found out that this part is not showing in the iphone with all the content inside the .
what I can use instead of tag?
I tried but all the styling gets off. Is the only tag replacing this so I may work more on style sheet or you are suggesting something else? Or even if the reason for not showing is the ?
I believe the "holder" attribute in your textboxes should be "placeholder" instead.

Submit by pressing enter asp.net

I am wondering why this, submitting on pressing enter, is only working on ie and not on google chrome...
This is the code I use actually :
<div class="TxtBox">
<asp:Panel ID="lepanel" runat="server" DefaultButton="Connect">
<asp:TextBox ID="TxtUserLogin" runat="server" TabIndex="1" Text="login" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="TxtUserLogin"></asp:RequiredFieldValidator>
<asp:TextBox ID="UserPass" runat="server" TabIndex="2" Text="password" TextMode="Password" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
Display="Static" ControlToValidate="UserPass"></asp:RequiredFieldValidator>
<asp:LinkButton ID="Connect" runat="server" OnClick="Connect_Click" TabIndex="3">connect</asp:LinkButton>
</asp:Panel>
<asp:Label ID="MsgError" runat="server" />
<div class="ForgottenPass">
forgotten password ?
</div>
<div class="RememberMe">
<asp:CheckBox runat="server" ID="chkBoxRemember" />
stay signed in
</div>
</div>
A LinkButton renders as a HTML anchor tag.
HTML anchor tags do not submit HTML forms. Therefore when you click Enter, this is not actioning any submit button.
A Button renders as HTML <input type="submit" />
An ImageButton renders as HTML <input type="image" />
These elements will both action your form.
Therefore changing LinkButton to Button or ImageButton is the best solution.
Using a LinkButton is also bad for users who do not have javascript enabled.
This is a known issue, when you add as default a link button (actually a link) and not a real button then there is a case that is not trigger properly.
So if you change it to real button you make it work.

Categories

Resources