label is not getting value from code behind asp.net vb - asp.net

I using java script to load the data show in asp Label. the result will be
01/01/2016 12:00 AM - 01/25/2016 12:00 AM
When I try to use asp.net code behind to get the label result by clicking button and showing msgbox result showing me empty.
<asp:Label ID="lblreserve1" runat="server" Visible="true"></asp:Label>
code behind
MsgBox(lblreserve1.Text)

<asp:Label ID="lblreserve1" runat="server" Visible="true"></asp:Label>
you are trying to get "text" property from an element that does not have "text"
you need to add the property and a value:
<asp:Label ID="lblreserve1" runat="server" text="Hello World" Visible="true"></asp:Label>

Related

Image not getting displayed in datalist

I am binding images to datalist. Taking the image name from database and giving the path.
My code is:
<asp:DataList ID="dlImages" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" Height="200px" Width="200px" ImageUrl='<%# Eval("PageName","D:\Sagar\Kinston\WebSite\ScreenMasterImages\{0}.jpg") %>' runat="server" />
</ItemTemplate>
</asp:DataList>
On .cs page:
ds = gc.GetDataToListBinder("select DISTINCT PageOrderID,PageName from ScreenMaster order by PageOrderID")
dlImages.DataSource = ds.Tables(0)
dlImages.DataBind()
I am facing 2 problems :
When imagename has space in between it adds %20 in between
Eg. if imagename is "API Message", it takes it as: "API%20Message"
I tried On this Problem:
Added ImageUrl='<%#Server.HtmlDecode(Eval("PageName","D:\Sagar\Kinston\WebSite\ScreenMasterImages\{0}.jpg"))'
But I got error:
XML literals and XML properties are not supported in embedded code within ASP.NET
If there is not space Eg.image name is "Charges" , Then also its not showing it in datalist.
When i ran project, and right clicked on it and view source, then its showing me correct path as:
src="D:\Sagar\Kinston\WebSite\ScreenMasterImages\Charges.jpg"
but not showing image.
Please help me with above code.
Where i have made mistake?
What else i should add in it?
Keep it easy and simple.
When trying things like that with URL, to know exactly what to write down, try typing it in your address bar so you'll be able to find the exact syntax needed in order to make it work correctly.
I've done this tons of time and work for me... So you could try something like :
<asp:DataList ID="dlImages" runat="server" RepeatColumns="4">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" Height="200px" Width="200px"
ImageUrl='<%# String.Format("{0}{1}.jpg", "~\ScreenMasterImages\", Server.HtmlDecode(Eval("PageName"))) %>'
runat="server" />
</ItemTemplate>
</asp:DataList>

Stop Postback in Image Button after validation failed

I have a aspx page containing a text box and an image button for search. I have used compare validator (to check for integer values) with the textbox. But the page reloads on the image button click even if I enter alphanumeric characters, along with showing the error message.
I tried using a regularexpressionvalidator instead but the problem persists.
But when i used a simple asp:button instead and binded it with textbox validation, its working fine (i.e. postback does not occur on incorrect value of textbox) and same is true with dropdownlist also (no postback occuring).
Please suggest.
Here's the code-
#peroija : Here's the code
<asp:ImageButton ID="btnSearch" runat="server" OnClick="btnSearch_Click"
ToolTip="Search" ValidationGroup="valControl" CausesValidation="true" />
<asp:TextBox ID="txtWidth" CssClass="TextFont" runat="server"
Width="233px" MaxLength="20"
ValidationGroup="valControl" CausesValidation="true"></asp:TextBox>
<asp:CompareValidator runat="server" ID="cmpValWidth"
ErrorMessage="Please enter integer values" ControlToValidate="txtWidth" Display="Dynamic"
Operator="DataTypeCheck" ValidationGroup="valControl"Type="Integer"/>
Sounds to me like you need to write
if(!isPostBack)
{
"your code"
}
in the code behind. To prevent the code from being run if the page is not viewed for the first time
Remove this from your textbox, you only need it on the validator and the button:
ValidationGroup="valControl" CausesValidation="true"
If javascript is disabled, then there will be no client side validation, so always check the validity on the server side also:
if(Page.IsValid)
{
"your btnSearch_Click code"
}

AJAX Calendar Extender / Textbox values always null after postback

Im sure this is a very simple and easy to answer question but I've been looking at this too long and being new to ASP I cant seem to find a solution that works.
I have an ASP calendar extender, I click it and the calendar displays as expected, the selected date appears in the textbox, but when the page then posts back I cant get the selected date value from either the textbox.text or the calendarextender.selecteddate properties, I tested this by trying to assign these values to a string variable in the page_load event.
Am I missing something here?
Here is my code so far:
I have the script manager declared at the start of my form
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
Then my textbox / datepicker within table lower down
<asp:TextBox ID="DateChooser"
runat="server"
ReadOnly="true"
style="text-align: center" Width="85px"
OnTextChanged="DateChooser_TextChanged"
AutoPostBack="true" />
<div style='position:relative; z-index:1'>
<cc1:CalendarExtender CssClass="cal_Theme1"
ID="DateChooser_CalendarExtender"
runat="server"
Enabled="True"
TargetControlID="DateChooser"
PopupPosition="Right"
Format="dd MMM yyyy"
/>
</div>
</td>
Since you have set textbox ReadOnly to true it lose changes performed by client-side code on postback. Follow this link for more detailed explanation: TextBox.ReadOnly Property Consider to set readonly attribute on textbox by client code.

Problems with confirm on ASP.NET

This is very weird, i have an asp:ImageButton inside a list view and i want to confirm and action before i execute the method but i can't
then i created another imagebutton outside the list view and the confirm does work can u guys tell me why?
this doesn't work
<asp:ImageButton ID="btnEnabled" OnCommand="CommandExecution" OnClientClick="return confirm('Desea eliminar el cliente ?');" ImageUrl="~/App_Themes/Default/images/Habilitar.png"
Visible='<%# Eval("IsEnabled") %>' CommandName="ChangeStatus" ToolTip="Deshabilitar distribuidor"
runat="server" CommandArgument='<%# Eval("IdClient") %>' />
this one does
<asp:ImageButton ID="btnConfirmacion3" ImageUrl="~/App_Themes/Default/images/Habilitar.png" runat="server" Text="Confirmacion 3" OnClientClick="return confirm('Desea eliminar el cliente ?');" />
Set AutoPostback to false. then create two hidden textboxes for command name and params. then place a hidden linkbutton in page. in onclientclick event of your image buttons after confirm place command name and params in hidden boxes and then call postback method of link button. then handle command in link button event handler.

ASP.NET Event Handler for label in Datalist

I'm working on an ASP.NET page, and have a DataList with a non-visible label, ID, inside of it. The Datalist is populated by Query A.
I'm trying to add a handler in my VB code where it will run Query B, populating a different label in the Item Template, after ID is changed. I figure I need to go somewhere in the DataList, but poking through Intellisense and a google search weren't successful. Does anyone know how I get to that label? Sorry if this is a dumb question, and thanks for the help.
Edit: I see how I can access the datalist items while inside the function, but how do I do it for only one part of the DataList control in the Event Handler? All the options I'm seeing are related to full events involving the Data List, not a single label changing. Thanks.
Edit 2:
I figured I'd add some code, to better explain exactly the exact issue I'm having.
<asp:DataList ID="DataList1" runat="server" DataSourceID="Omitted,Ilikemyjob">
<ItemTemplate>
<asp:Label ID="FromLabel" runat="server" Font-Size="Small" Text='<%# Eval("IncdntDate") %>'></asp:Label><br />
<asp:Label ID="ToLabel" runat="server" Font-Size="Small" Text='<%# Eval("Roadway") %>'></asp:Label><br />
<asp:Label ID = "lblCrossroad" runat ="server" Font-Size = "Small" Text = '<%# Eval("Crossroad") %>'></asp:Label><br />
<asp:Label ID = "lblRdwyID" runat ="server" Font-Size="Small" Visible = "false" Text = '<%# Eval ("RdwyID") %>'></asp:Label>
<asp:Label ID = "DistanceLabel" runat ="server" Font-Size = "Small" Text = '<%# Eval("RptTime") %>'></asp:Label><br />
<asp:Label ID = "lblTTime" runat ="server" Font-Size = "small" visible ="false"></asp:Label>
<hr />
</ItemTemplate>
</asp:DataList><br />
There's the DataList thing I'm doing, and I have a different query that I want to store the value of to lblTTime if lblRdwyID is set to a certain range of values, thought it will not always be set to a value.
I'm trying to set up an event that will trigger when lblRdwyID is set, that will launch the other query and set the value of that templated items lblTTime and make it visible. Is there a good way to do this? I tried messing around with DataList1's events, but couldn't get anything to do the trick.
If your label has its visibility set to false, it won't render on the screen (as opposed to having a div block with visibility set to hidden), and so I wager that is why you can't actually find the control after the binding has occurred.
Have you tried using the DataKey property to store the ID instead? It is easily accessible at the row level and you can store additional data if needs be.
Assuming you have the row, you use:
row.FindControl("mylabelid")

Resources