ImageButton with PostBackUrl responds after the second click issue - asp.net

Hello i have a problem with my Imagebutton i have to double click just to get it to post any one know how i can fix it so i only have to click it once to get a response?
thank you for your help!
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:smokeshopConnectionString %>"
ProviderName="<%$ ConnectionStrings:smokeshopConnectionString.ProviderName %>"
SelectCommand="SELECT ProductID, Name, Description, Price, ImageUrl FROM products"></asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
RepeatDirection="Horizontal"
DataKeyField="ProductID" >
<ItemTemplate>
<div style="border-style:dotted; border-color:WhiteSmoke;">
<a onclick="popup('popUpDiv')" href="#" ><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# Eval("ImageUrl", "Images\\{0}") %>' PostBackUrl='<%# Eval("ProductID", "Default5.aspx?ProductID={0}") %>' /></a><br />
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label><br />
</div>
</ItemTemplate>
</asp:DataList>

I have test code from side ..its works fine ..I got image button event in single click. I think problem is with javascript function written over imagebutton i.e.
popup('popUpDiv')
Can you please explain javascript function "popup('popUpDiv')" .. or you can test it with remove anchor link tag from image button..

Related

Cannot access Ajax Rating from code behind

I have this html markup:
<div id="profil_rating_container">
<div id="profil_rating">
<div id="pr">
<h2 id="rating" class="profil_rating_title">Hodnocení <asp:Label ID="lblAddRating" runat="server"><span><i class="fa fa-plus-circle"></i></span></asp:Label></h2>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<ajaxToolkit:Rating ID="FinalRating" runat="server" MaxRating="5" ReadOnly="true" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="mainFilledRatingStar" EmptyStarCssClass="mainEmptyRatingStar" />
<br />
<asp:SqlDataSource ID="RatinSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SportovniPlanetaCS %>"
SelectCommand="SELECT [RatingText], [RatingCount], [Name] FROM [rating] WHERE ([ProfileId] = #ProfileId) AND ([RatingText] IS NOT NULL)">
<SelectParameters>
<asp:QueryStringParameter Name="ProfileId" QueryStringField="id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Repeater ID="RatingRepeater" DataSourceID="RatinSqlDataSource" runat="server" OnItemDataBound="RatingRepeater_ItemDataBound">
<ItemTemplate>
<h4><asp:Literal ID="RatingName" runat="server" Text='<%# Eval("Name") %>' /></h4>
<p class="p_rating"><asp:Literal ID="RatingText" runat="server" Text='<%# Eval("RatingText") %>'></asp:Literal></p>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblRating" runat="server" Text="Uživatel zatím nemá žádné hodnocení." Visible="false"></asp:Label>
</FooterTemplate>
</asp:Repeater>
</div>
</div>
</div>
And when I am accesing Ajax Control Toolkit Rating from code behind like this: FinalRating.CurrentRating = cmdRating.ExecuteScalar it underline FinalRating with error text: 'Final Rating' is not declared. It may be inaccessible due to its protection level.
I don't know why this is happening. I have the same code in other 5 pages and it is working finec, but in this one page it isn't. Also when I add new page and add Ajax Rating, I cannot access it from code behind. The rating control isn't in any data component like repeater or datalist. Can this be solved by FindControl? If yes, how exactly?
Does anyone know, what is causing this problem? Thanks for answer.

Replace in ASP.net

i'm new to asp.net and i'm struggling with the replace function that i'm hoping someone can help with. When i use some test text it works fine (as in the example below) but as soon as i replace the test text with the value from the database (Eval("PContent")) i get a databinding error. The label separately works fine.
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
I've tried al-sorts but i cannot get around this.
Here's my code:
<asp:Label runat="server" ID="Label4" text='<%# Eval("PContent") %>' />
<%
Dim text1 As String = "Some text here [q]testing[/q]"
Dim output As String = text1.Replace("[q]", "<span class='quote'>")
Dim VS As String = output.Replace("[/q]", "</span>")
Response.Write(VS)
%>
Thanks for your time - sorry if this is a very n00b thing to ask! I did try search for an answer on here and google but i can't find anything...
**Update....
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label runat="server" ID="Label5" text='<%# Eval("PMonthName")%>' />
<asp:Label runat="server" ID="Label6" text='<%# Eval("PDay")%>' /></small>
</div><!--middlebartext -->
<div class="middlebartexttitle"><a href="/Details.aspx?ID=<%# Eval("BID")%>">
<asp:Label runat="server" ID="Label3" text='<%# Eval("Header")%>' /></a><br />
<asp:Label runat="server" ID="Label4" text='<%# Eval("PContent")%>' />
Permalink
<div class="ruler"></div>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource
ConnectionString="<%$ ConnectionStrings:Conn2 %>"
ID="SqlDataSource1" runat="server"
SelectCommand="SELECT * from tablename where Deleted = 'False' Order By DateAdded DESC"
onselected="SqlDataSource1_Selected">
</asp:SqlDataSource>
I've cut a chunk of code out so it's not as long :)
It's another way to do the replace more short:
C#
<%# ((string)Eval("PContent")).Replace("[/q]", "</span>") %>
VB.net
<%# (Eval("PContent").ToString().Replace("[/q]", "</span>") %>
I don't know a lot Vb.net but I think the code above works.
I hope that help you.
I don't see PContent defined in your question, but
it would be simpler to do something like,
Label4.Text = [value from db]
You could set the text after you have fetched the records from database
Try changing this:
<div class="middlebartexttitle"><a href="/Details.aspx?ID=<%# Eval("BID")%>">
<asp:Label runat="server" ID="Label3" text='<%# Eval("Header")%>' /></a><br />
<asp:Label runat="server" ID="Label4" text='<%# Eval("PContent")%>' />
Permalink
To:
<div class="middlebartexttitle"><a href='/Details.aspx?ID=<%# Eval("BID")%>'>
<asp:Label runat="server" ID="Label3" text='<%# Eval("Header")%>' /></a><br />
<asp:Label runat="server" ID="Label4" text='<%# Eval("PContent")%>' />
<a href='/Details.aspx?ID=<%# Eval("BID")%>'>Permalink</a>
Since Eval requires quotes for the field it's evaluating, my guess is that the quotes you have defining the href attributes are throwing it off. Change those to single quotes (like you have everywhere else) and see if that works.
Also, you can learn more about inline expressions (and when to use them) at http://support.microsoft.com/kb/976112

Data Pager + Update Panel + list view

I need help, I have a DataPager inside the update panel and and working well, but when I refresh page or going on back button form some other page DataPager reset always to the first page.
For example if I was on the tenth page and refresh page, data pager reset to first.
Is there any way to keep the current page on data pager?
My code is:
<asp:SqlDataSource ID="SqlDataSource1" EnableCaching="True" CacheDuration="4000" CacheExpirationPolicy="Sliding"
runat="server" ConnectionString="<%$ ConnectionStrings:blabla %>" SelectCommand=""></asp:SqlDataSource>
<asp:UpdatePanel ID="UpdatePanelnajgornji" runat="server" >
<ContentTemplate>
<asp:ListView ID="ListView1" runat="server" ondatabound="ListView1_DataBound" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" Visible='<%# !(Eval("Slika") is DBNull) %>' runat="server" NavigateUrl='<%# Eval("Link") %>' title='<%# Eval("Naslov") %>'>
<asp:Image ID="Image1" runat="server" AlternateText='<%# Eval("Naslov") %>' ImageUrl='<%# Eval("Slika") %>' /></asp:HyperLink>
</ItemTemplate>
</asp:ListView>
<br />
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1">
<Fields>
<asp:NextPreviousPagerField />
</Fields>
</asp:DataPager>
</ContentTemplate>
</asp:UpdatePanel>
Browser refresh creates new objects (and thus clears the state of the DataPager). You need to save the current page either in the Session or the ViewState, then initialize the control using those values if they exist in the codebehind. Store the values in an unload event listener.

FormView.FindControl works for one form but not the other on the same page

I have two Formviews on the same page. I can use FindControl on the first without issue, but it always fails on the second one.
I am using the ItemTemplate for both, both default to ReadOnly, both are bound to SQLDataSources (different ones) but I cannot for the life of me work out why FindControl works for one and not the other.
I have removed a lot of the plain text from the code below.
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Apps] WHERE ([AppID] = #AppID)" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="AppID"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<h1>
<asp:Label ID="AppNameLabel" runat="server" Text='<%# Bind("AppName") %>' />
<asp:Label ID="VersionLabel" runat="server" Text='<%# Bind("Version") %>' /> for
<asp:Label ID="OSLabel" runat="server" Text='<%# Bind("OS") %>' />
</h1>
<p>Text here</p>
<p><asp:TextBox ID="LicenseTextBox" runat="server"
Text='<%# Eval("License")%>'
TextMode="MultiLine" Width="800px" Rows="25" ReadOnly="True"></asp:TextBox></p>
<asp:HiddenField ID="AppLocation" runat="server" ViewStateMode="Inherit" Value='<%# Bind("AppLocation") %>'/>
</ItemTemplate>
</asp:FormView>
<p><asp:Literal ID="SizeLiteral" runat="server"></asp:Literal></p>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:SoftSaleDBConnectionString %>"
SelectCommand="SELECT * FROM [Installations] WHERE (([AppID] = #AppID) AND ([Username] = #Username))" >
<SelectParameters>
<asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" />
<asp:FormParameter FormField="Username" Name="Username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="DLFormView" runat="server" DataSourceID="SqlDataSource4"
DataKeyNames="AppID,Username">
<ItemTemplate>
<p> <asp:Label ID="DLAppNameLabel" runat="server" />
<br />
<br />
<asp:Label ID="NumberOfInstallations" runat="server" Text='<%# Bind("Installations") %>'></asp:Label>
<br />
<asp:HiddenField ID="TotalInstallations" runat="server" />
Number of New Installations:
<asp:DropDownList ID="NumberOfNewInstallations" runat="server">
</asp:DropDownList>
<br />
<asp:Label ID="TotalNumberOfInstallations" runat="server" Text="Label"></asp:Label>
</p>
</ItemTemplate>
</asp:FormView>
And the FindControl coding is as follows...
TextBox LicTextBox = (TextBox)FormView1.FindControl("LicenseTextBox");
HiddenField AppLocCode = (HiddenField)FormView1.FindControl("AppLocation");
Label AppNameCode = (Label)FormView1.FindControl("AppNameLabel");
These always work...
Label DLAppNameCode = (Label)DLFormView.FindControl("DLAppNameLabel");
This always returns null. I've read a million bosts about the controls not being rendered until databinding has completed, but surely if the two FOrmViews are set up the same way, the result should be the same.
Any help would be much apreciated :)
Matt :)
I'd like to plead stupidity and but also provide some background to how I've used what I've learnt from my stupidity.
My SqlDataSource for DLFormView was returning records, of course I then used slightly different values by accident and so no records were returned. I only figured this out by making the ItemTemplate section of the form view only contain unbound (basically plain text) data. As nothing displayed, this pointed towards the page using a different tempalte. When I put a test line in the EmptyDataTemplate, it displayed, confirming there was nothing returned by the SqlDataSource. Perhaps a School boy error not putting something in this template during development.
As it happens I need to use the EmptyDataTemplate anyway, I just hadn't got to this point. As only one template is rendered at a time, I have been able to use the same ID names in both templates. This means there is no need to test for which template is being used. (although empty template is used when DataItemsCount = 0, otherwise you can test for CurrentMode for the remaining templates.)
So a big fail on my part, but I hope people can learn from my mistake.
Matt :)

ASP.net databinding a hyperlink from Access DB fields

I am helping my daughter build an asp.net website that has an Access database. We are using a DataList with a couple fields inside the ItemTemplate. The one that is giving me trouble is the Hyperlink. The code is below. When the page loads the hyperlink renders like this:
<a id="ContentPlaceHolder1_DataList1_lnk_6" href="#http://www.washingtonfaire.com/#" target="_blank">Washington Midsummer Renaissance Faire</a>
But when I click on the link, it tries to navigate to "http://localhost:1852/BOOMPiratesB/Raids.aspx#http://www.washingtonfaire.com/#"
What are we doing wrong?
Here is our code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1">
<ItemTemplate>
<asp:HyperLink id="lnk" runat="server" NavigateUrl='<%# Eval("Link") %>' Target="_blank" Text='<%# DataBinder.Eval(Container.DataItem, "VenueName")%>'>
</asp:HyperLink>
<br />
<asp:Label ID="DateTextLabel" runat="server" Text='<%# Eval("DateText") %>' />
<br />
<asp:Label ID="CityStateLabel" runat="server" Text='<%# Eval("CityState") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/my.mdb"
SelectCommand="SELECT [VenueName], [Link], [DateText], [Season], [DateStart], [CityState] FROM [qpgRaid]">
</asp:AccessDataSource>
I cannot see where the extra # signs are coming from. They don't appear to be in the field in the table.
It's very puzzling. And insight would be most appreciated.
Have a look at this question
I guess you are using an access hyperlink column to store the link. If you convert it to a text column it should start working fine, or you may have to strip the '#'s manually.

Resources