ASP.Net Label control's Text property not updating text under button click event - asp.net

I have developed a small application in SharePoint. I am using custom application page and load .ascx Control over that page under Page_Load() method. In .ascx Control, I have created a small form with text boxes and a button Control. under this button click event, I want to change the text property of label like: lblConfirmation.Text = "Confirmation is OK"; but it did not change the text. It shows nothing because i set text property empty in label Control.
<asp:Label ID="lblConfirmation" runat="server" Text="" ></asp:Label>
Any Idea, what is wrong ?

What are this single quotes in your asp:Label definition ? please check this
<'asp:Label ID="lblConfirmation" runat="server" Text="" ><'/asp:Label>
it must be replaced by
<asp:Label ID="lblConfirmation" runat="server" Text="" ></asp:Label>
Try to debug the code in your visual studio and let us know if you get any error ?
Thanks

Related

Adding a click event to a Hyperlink displayed in ListView VB.NET ASP.NET

Is there a way to add a click event to a Hyperlink tag that's render in ListView?
Basically, I have a HyperLink tag that generates a link dynamically and it opens up to a new tab when users click on it. At the same time, when the user click on it, I want to post a text or make the text label visible. Sample code below:
<asp:ListView ...>
<ItemTemplate>
<asp:Label ID="Msg" Text="*You have already accessed this link*" runat="server" Visible="false"/>
<asp:HyperLink ID="label1" NavigatUrl='<%#Eval("Link")%>'Target="_blink" text="Click Link" runat="server"></asp:HyperLink>
<//ItemTemplate>
</asp:ListView>
You can use QueryString. Add the link with a Query Parameter on it and then -
If IsPostBack=True then 'Check if the page is reloading [Because when you clik on the link with the same link, it will reload the page]
'Considering the QueryString will be like - "yourdomain/default.aspx?item=1"
'Check for QueryString
Dim s_ItemId As String = Request.QueryString("item")
if s_ItemId<>"" then
'Do whatever you want
End If

RequiredFieldValidator Control displays the Error Text on Page_Load

I am having trouble with the <asp:RequiredFieldValidator> in this code.
<asp:Label ID="email_Label" runat="server" Text="Email"></asp:Label>
<asp:TextBox ID="email_Text" runat="server" MaxLength="40" Width="250"></asp:TextBox> *
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="email_Text" Text="Required"></asp:RequiredFieldValidator>
According to the W3schools documentation here I have used the <asp:RequiredFieldValidator> correctly, however instead of displaying the label and text box the page also displays the error message. This happens on page_load so the value has not had a chance to change from the default yet. I want the error text to display after the user clicks the Save button at the bottom of the form I am building.
What is Being Displayed:
Email[TextBox] * Required
What Should Be displayed:
Email[TextBox] *
Am I missing a parent element for the validator or something. According to the example on w3schools site no parent element should be needed. In fact the way they have their example set-up is exactly what I was expecting for this.
Use Validation Group if want to display Error message on Button click. Like this.
<asp:RequiredFieldValidator ID="rqtxtQName" ValidationGroup="save" ControlToValidate="txtQueueName" runat="server" ErrorMessage="Some required field are missing." SetFocusOnError="True"Display="Dynamic"></asp:RequiredFieldValidator>
and use validation group on Button also.
<asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="save" OnClick="btnSubmit_Click"/>
Hope it will helps.
you should use ErrorMessage instead of Text
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="email_Text" ErrorMessage="Required"></asp:RequiredFieldValidator>
If you want to validation on save button click event then set property ValidationGroup="Group1"
for RequiredFieldValidator and also for save button. So it will check validation when you click save button.
And For display message you can use ErrorMessage property.
Thanks,
Hitesh
Set the RequiredFieldValidator this way. Remove the property: 'TextRequired' & put a * inbetween the opening and closing tag.
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="email_Text">*</asp:RequiredFieldValidator>
Also, Do not set the ErrorMessage property as this will again not fit your requirements.

Add a linkbutton (hyperlink) to Text attribute of a Control in ASP.net

I am working on ASP.net page and is there a way I could add a linkbutton to Text attriubte of another control, say a checkbox. So something like this,
<asp:CheckBox ID="chkAccept" ForeColor="Red" Text="Check this box if you can see <linkbutton onclick-"dosomething()> this popup</linkbutton></asp:CheckBox>
Here, user will see the text in checkbox but, "this popup" will be a linkbutton to open a popup.
Thanks for any help in advance.
You can't have a control inside the attribute of another control. What I would do is take the text out of the control and have it appear as separate markup after the control. Then you can do whatever you want.
<asp:CheckBox ID="chkAccept" ForeColor="Red" />
<span>Check this box if you can see <asp:LinkButton OnClientClick="dosomething()" Text="this popup" />.</span>

Eval property and extra text on a button's text property

I'm using an asp Button like follows:
<asp:Button id="someButton" runat="Server" Text='<%# Eval("Size") %>' />
This is great but before the Eval Property result I wanted to add the Text "Download " with possibly the units after it.
eg. Download 123KB.
Can someone please tell me how to go about this?
In this case it might be easier to set the text property of the button on the server in the page load event.
insted of button use linkButton.
**asp:LinkButton ID="HyperLink2" OnClick="HyperlinkSelectedCustomers_Click" runat="server" CommandArgument='<%#Eval("id") %>' ><%#Eval("selectedCustomers") %>/asp:LinkButton

Detecting Enter in TextBox ASP.NET no JavaScript Please

Basically I have a Search Text Box with a LinkButton Control on which the click event is fired. now what i want is when the user type keywords and press enter the Click event got fired.
So No Javascript Only ASP.NET With VB.NET v2.0
Sincerely
Rajeev
Rajeev_rsd#hotmail.com
Create a Panel that contains both the TextBox and LinkButton. The Panel has a property called DefaultButton, set DefaultButton equal to the ID of the LinkButton.
<asp:Panel id="panel" runat="server" DefaultButton="linkButton">
<asp:TextBox id="search" runat="server"/>
<asp:LinkButton id="linkButton" runat="server"/>
</asp:Panel>
Can you not just use AutoPostback on the textbox?

Resources