postback when scrolling ListBox in chrome - c#

with scrolling list box, the page will refresh(unwanted).
this problem is only in chrome (Version 27). In other browsers it works properly.
.aspx file:
<asp:Label runat="server" ID="label1" ></asp:Label>
<asp:ListBox ID="ListBox1" runat="server"
OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"
DataValueField="f1" DataTextField="f2" DataSourceID="SqlDataSource1"
Rows="15" AutoPostBack="true" >
</asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="sp1" SelectCommandType="StoredProcedure"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>">
</asp:SqlDataSource>
.cs file :
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = ListBox1.SelectedItem.Text;
}

We've noticed this unfortunate bug only recently, on a page that had been working without issue for a very long time. It is specific to Google Chrome version 27, and I am currently using version 26.
The bug:(clicking anywhere inside of the control - the scroll bar being the focus of the issue - causes a complete postback [provided you set the AutoPostBack attribute to true])
The bug could be at a higher level of scripting, and I'm not sure it affects all of our listboxes. It seems unlikely as we have many, on multiple pages, and we would be getting calls if all of them exhibited this behavior.
Our solution contained two options, with another option being less classy:
1) Impractical: to wait for an update for Google Chrome, or use version 26 explicitly. This is impractical for a large userbase which doesn't have permissions for installation or the ability to roll back to a previous version. It also doesn't work if you, for whatever reason, absolutely must test against the latest version of Chrome.
2) We have access to Telerik controls which enable us to use RadListBox instead, slightly more viewstate overhead which may not be a good solution for you, if it's an option at all. This was the option we chose, as the RadListBox escapes the problem behavior.
A distant third, substantially less appealing solution: Find some other alternative for displaying your data, such as a dropdown list, possibly with a secondary subselecting control if you're dealing with a particularly large set of information. It's more work, in the interim, and you would likely wish to revert your changes when a fix was made.
I know all of these are mediocre solutions, but they're possible workarounds. Sorry if this isn't much help.

This is a bug in some Chrome versions (as others have noted). I was getting the same behaviour on Chrome on an earlier v27 release.
You should upgrade Chrome to the latest version: my version is currently v 27.0.1453.116 m and the problem appears to be fixed in this release.

This is an issue in v27 of Chrome, updating to the latest version should fix this.
http://googlechromereleases.blogspot.co.uk/2013/06/stable-channel-update_18.html

The JavaScript function mypostback doesn't work if the listbox has SelectionMode="Multiple"

Disable the AutoPostBack for the ListBox, use the onClick attribute of the ListBox to run a javascript doing __doPostBack for it. It is a work around. I think Google should fix this Chrome bug (ver 27, and 28, ...). It, AutoPostBack True of ListBox, works fine at all other browsers. TY Pien.
<script type="text/javascript">
function mypostback(id, parameter)
{
__doPostBack(id, parameter)
}
</script>
<asp:ListBox ID="lstbox_id" runat="server" onclick="mypostback('lstbox_id','')">
</asp:ListBox>

It's definitely a bug in Chrome (e.g. v.27.0.1453.110 m). See this answer too.

Related

Binding Image URL with RadImageButton

I asked on Telerik's site, but there is apparently not enough traffic there to generate answers.
I am trying to convert an asp ImageButton to a RadImageButton because there are some useful features that would make my life a bit easier. However, the binding for the image URL won't work - at least the way I am doing it.
So this works (both are in the same ListView):
<asp:ImageButton ID="im" runat="server" ImageUrl='<%# Eval("ImgUrl") %>' />
But this:
<telerik:RadImageButton runat="server" ID="itemImageButton" '>
<Image Url='<%# Eval("ImgUrl") %>' />
</telerik:RadImageButton>
gives me an error something like Telerik.Web.UI.ButtonBase.ButtonImage does not have a DataBinding event.
If someone could point me in the right direction to get this done with the RadImageButton control (if possible), I would appreciate it.
I was recently facing exactly the same issue. Apparently child objects/properties in some controls are not DataBound-able.
You have to do the binding for the image URL inside the telerik:RadImageButton tag itself, so instead of using <Image Url="" /> section, place it in the Image-Url attribute:
<telerik:RadImageButton runat="server" ID="itemImageButton" Image-Url='<%# Eval("ImgUrl").ToString() %>'>
</telerik:RadImageButton>
You can ommit .ToString() part though.
One more "issue" that I've got when switching from asp:ImageButton to telerik:RadImageButton was the necessity to set the width and height explicitly. Without it, it didn't work ouf of the box. Image (icon) was malformed, even though it was like 24x24 sized. I ended up setting width="" and height="" attributes, but adding CssClass and using styles should work too.

Double pass required for TextBox Postback in FormView

This is a follow up to an earlier issue which I provided my own answer to but there is a new wrinkle in the process that I'm looking for an answer.
Scenario:
Have a asp.TextBox embedded inside of a asp.FormView control. Prior issue was that I couldn't populate the TextBox from code behind (C#). This was corrected by adding AutoPostBack = "true" to the TextBox.
Issue:
The postback corrected the population of the Text box but now two passes on the control assignment have to be executed in order to see the textbox populated.
Specific Question
How can correct this so it doesn't require a second click of the button to see the textbox populated.
Code Examples:
/*-- This is the fragment of code in the aspx which is related to the issue: --*/
<asp:FormView runat="server" ID="EditImpStndPreamble" DataSourceID="ImpStndPreambDS" OnItemCommand="EditImpStndPreamble_ItemCommand" DefaultMode="Edit" DataKeyNames="ARS_Index">
<InsertItemTemplate>
<asp:Label runat="server" Font-Size="Small" Font-Bold="true" Width="60" Text="Index #"></asp:Label>
<asp:Label Text='<%# Eval("ARSEL_Index") %>' runat="server" ID="ARSEL_IndexLabel1" Width="74" />
<asp:Label runat="server" Width="60" Font-Size="Small" Font-Bold="true" Text="Control #"></asp:Label>
<asp:TextBox Text='<%# Bind("ARSControlNum") %>' runat="server" ID="ARSControlNumTextBox" Width="74" />
<asp:LinkButton runat="server" Text="Insert" CommandName="Insert" ID="InsertButton" CausesValidation="True" /> <asp:LinkButton runat="server" Text="Cancel" CommandName="Cancel" ID="InsertCancelButton" CausesValidation="False" />
</InsertItemTemplate>
</asp:FormView>
// This is the fragmentof code in the C# code behind related to the issue
// This is where we update the control number
Label ctrnum = (Label)EditElementsFV.Row.FindControl("ARSControlNumLabel");
if (ctrnum != null)
ctrnum.Text = Session["CurrentControl"].ToString();
Any insight here would be welcomed. I've tried several things but haven't come up with a means of making this work like I want it to. I'm thinking if I could trigger a second postback of only the TextBox control here that could resolve it. The problem is every method of doing a postback from code behind seems to reset the page which by default has this FormView invisible.
Regards,
Updated 03/24/17 1:06PM Central US:
I took a bit of a break from this issue to work on another segment of the project. I tried several more thing but the last thing I did was track several variables through the debugger and examine the flow of the code as I stepped through the pertinent sections of code.
To the double tap issue I discovered that the first time you click on the Insert Implementation Standards button that the execution was routed through 'Item Template' of the FormView and then it ran through the 'Insert Template' before coming to rest.
Conversely the second click of the button executed as I would have expected and ONLY executed the 'Insert Template of the FormView.
I also observed all the variables that are used in the DataSource related to the FormView being properly populated prior to the execuation of either the Item Template and/or the Insert Template of the FormView.
So, this is even more baffling that I originally ran into it because at first all that I was dealing with was the lack of visibility of two TextBoxes, now however, we have the curiosity of the code executing the Item Template of the FormView prior to walking through the Insert Template.
Ken...
Updated: 03/27/17 9:55AM Central US
I have been working on this and searching for examples of similar issues that I might be able to leverage from and so have now attempted using a FormView.ItemInserting block (Which is bypassed prior to actual execution of the 'insert') and FormView.DataBound blocks. The DataBound was able to trigger but I had to encompass the block in a conditional 'if (IsPostBack)' to avoid trigging a null reference error. This properly routed through the block however the result on the screen draw was the same wit the fields not being populated as intended. Here is the last block as last attempted:
protected void EditElementsFV_DataBound(object sender, EventArgs e)
{
if (IsPostBack)
{
Label ctrnum = (Label)EditImpStndPreamble.Row.FindControl("ARSControlNumLabel");
if (ctrnum != null)
ctrnum.Text = Session["CurrentControl"].ToString();
Label famlbl = (Label)EditImpStndPreamble.Row.FindControl("ColumnTagLabel");
if (famlbl != null)
famlbl.Text = Session["CurrentFamily"].ToString();
}
}
Pressing on but could really use some other eyes on this.
Update: 03/29/17 7:42AM Central US
I wanted to post this update yesterday but got pulled off on a different project for a bit. My latest attempt to resolve this issue I thought for certain that it would work. But it has also failed to load the values into the insert mode of the forum until the button has been selected the second time.
What this does is from the trigger of 'DataBound' in the FormView it directes the flow to a function FillDefaultValue which assigns default values to the two parameters that are in the FormView that control the TextBox displays.
In my mind this 'should have' resolved the issue as the default value would then be the values contained in the Session variables instead of being blank(null).
public void FillDefaultValueInFormView()
{
if (EditElementsFV.CurrentMode == FormViewMode.Insert)
{
EditElementsDS.SelectParameters["ARSControlNum"].DefaultValue = Session["CurrentControl"].ToString();
EditElementsDS.SelectParameters["ColumnTag"].DefaultValue = Session["CurrentColumn"].ToString();
}
}
protected void EditElementsFV_DataBound(object sender, EventArgs e)
{
if (IsPostBack)
{
FillDefaultValueInFormView();
}
}
So the mystery continues...
I ended up using the function FillDefaultValueInFormView() defined in the question to resolve this.
I watch in debut the flow over and over again and realized what was happening was that when I set the FormView's mode to Insert that it was flushing the value assignments that I was placing on the TextBox.
Then I realized that what I needed to do was assign the default value in the DataSource to be what I desired in the TextBox 'prior' to setting the mode of the FormVeiw to Insert. So, I added the call to the function in the early portion of my Button_click event immediately followed by changing mode of the FormView to Insert.
protected void AddImpStadBTN_Click(object sender, EventArgs e)
{
Session["CurrentColumn"] = "IMP";
FillDefaultValueInFormView();
EditElementsFV.ChangeMode(FormViewMode.Insert);
... More code follows to complete this but left off as it doesn't effect the results...
}
After doing this the change to insert mode on the FormView was successfully prepopulated as I had intended for the user. I'll now change them to ReadOnly so the user can't change them, making them programmatically driven fields within the form.

Ajax AutocompleteExtender troubles

I've been struggling all day with Ajax, and have no luck. I know this question title has been asked before, but I've been pouring over many other posts about this, and none have the solution for me. Let's start with the simplest scenario.
Having installed Ajax Toolbox, Version 15.1, I create a new web application, delete the content from the default page, drop a textbox onto it, and then try to drop an Ajax AutoCompleteExtender onto the textbox. Result = no effect on the webpage at all. The Toolbox has all the AjaxControlToolkit.15.1, but none of the Ajax controls can be dragged onto any forms. (Other controls can be dragged correctly - only the AjaxControlToolkit controls have no effect)
Moving on to the more complicated scenario, I've tried to implement this manually, by adding a reference to the AjaxControlToolkit to the project - which requires a HDD search to find the dll, and adding a reference to this.
After manually adding the reference, then I can create a new page, and by editing the aspx source, I can create an AjaxCompleteExtender which builds and runs, but does not function correctly. If I connect the AjaxCompleteExtender to a webservice, it does nothing. If I connect it to a local function, it gives a strange list of autocomplete entries as follows...
<
D
O
C
T
Y
P
E
h
t
m
... etc...
I have put breakpoints in my ServiceMethod functions, and they never get called.
Here is the webpage for the version with the in-page function.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ServiceMethod="AutoCompleteSymbol"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtBox"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</asp:AutoCompleteExtender>
And here is the code behind this page.
namespace Jug2013
{
public partial class TestForm : System.Web.UI.Page
{
[WebMethod]
[ScriptMethod]
public static string[] AutoCompleteSymbol(string partial, int count)
{
var retval = new List<string>();
retval.Add("Hello");
retval.Add("Hello2");
retval.Add("Hello3");
return retval.ToArray();
}
}
}
I have checked the code of this version and the web service version many times against online examples, and tried many different variations that I've found in sample code. In final desperation, I have uninstalled and reinstalled Ajax, but still no luck anywhere.

Better way to hide titles in Sitecore/ASP.NET

I'm using Sitecore and just getting the hang of working within ASP.NET. We don't have a second Sitecore license for a development server, so I have to do everything live fire on the site (ack!), so I am trying to avoid working with code behinds due to the necessity of a recompile/DLL insert.
I'm just trying to hide a section header if the following section is empty. I've come up with this, which definitely works, but it seems pretty bulky:
<% if (!string.IsNullOrEmpty(Sitecore.Context.Item.Fields["Grades"].ToString())) { %><h2 class="edu">Timeframe</h2><% } %>
<sc:FieldRenderer runat="server" ID="mhTimeFrame" Fieldname="Timeframe" />
Is there a more straightforward way to do this?
By the way: I'm aware that Sitecore can utilize XSLT templates but our site was built without utilizing XSLT so I'd like to stick to one paradigm so that a future developer can make sense of this.
Just to state the obvious, you need to get a proper development process in place or you will get yourself into trouble! If you haven't already, talk to Sitecore and figure out what you need in terms of licenses to get a proper development environment up and running. You may be entitled to a development instance if you are a certified developer.
Now, to your question, you have to put the logic somewhere. If you are unable to modify the codebehind, compile and deploy then you need to put it on the .ascx. You can trim it up a bit I suppose...
<% if (Sitecore.Context.Item["Grades"] != "") { %><h2 class="edu">Timeframe</h2><% } %>
<sc:FieldRenderer runat="server" ID="mhTimeFrame" Fieldname="Timeframe" />
In order to get rid of the if-statement in your markup, you can set the visible attribute of your <h2 /> element:
<h2 class="edu" runat="server" Visible='<%# Sitecore.Context.Item.Fields["Grades"] != null %>'>
Timeframe
</h2>
To get this up and running, you need to trigger the DataBinding at least one time:
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
}
Nevertheless you NEED a development environment ;)

Text with RegEx Validator not working

I have an issue with the following text display:
<asp:RegularExpressionValidator ID="Password_RegularExpValidate" runat="server"
Text="TEST!"
Display="Dynamic"
BorderStyle="None"
ControlToValidate="txtNewPass"
ValidationExpression="(?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*"
meta:resourcekey="Password_RegularExpValidateResource1" /></td>
The pattern by itself is:
(?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*
The text initially had some stuff in it as the ValidationExpression was different. I've changed the regex expression and that works, but when I write something in Text= it doesn't update on the page. I've restarted IIS, cleard the IE chache... everything I could think of. The old text keeps appearings (ie. "TEST!" doesn't show up when the validation fails as it should).
Any help would be appreciated.
Edit:
The code for txtnewpass:
<asp:TextBox ID="txtNewPass" runat="server"
TextMode="Password"
MaxLength="256"
meta:resourcekey="txtNewPassResource1"></asp:TextBox>
Also, it's worth noting that I can remove an entire table from a page that it disappears when I reload the page. But when I change text values from controls or anything that runat="server" and the page doesn't seem to update with the text....
And the code behind doesn't edit the field that displays, the validator validates the text in the textbox and uses that value later.
Edit 2: Same thing happening with -
<asp:Label ID="Label1" runat="server"
Text="Change Password!!!!!"
meta:resourcekey="Label1Resource1"></asp:Label></td>
I've added the exclamation marks (!!!!!) and that's not showing up when I refresh the page either.....
Edit 3: As I've noted in one of the comments, if I delete a table from the page and reload the page, that table disappears, so I know the page is reloading properly. The runat="Server" property, does that work a certain way where it caches text or something? I'm out of ideas....
Like Kirill said, use ErrorMessage instead of Text.
But the main problem is, I think, your localization, which is handled through the meta:resourcekey tag and resources.
Here is a good explanation:
ASP.NET meta:resourcekey
If you set automatically or manually the resource localization file and change something afterwards, for example a Label Text property, then you need to do it in the resource file too. Because there should be your initial value, which is loaded at runtime.
There are a lot of possibilities for the source of the problem, and there's not really enough info to tell which one it is. It sounds to me like one of these:
1) An external issue with your application or page (perhaps your ViewState isn't being set up properly, or the validation is getting called before PostBack).
2) You should be using RegularExpressionValidator.ErrorMessage instead of Text, as Kirill suggested. You said that you had changed that, but I wonder if you've reloaded the page (you could try rebuilding the app or something if it's getting cached somehow).
3) Your regex might not be doing what you think it is. The pattern is extremely long, and it seems strangely written. Adding some whitespace, we find that it looks like this:
(?=^.{8,255}$)
(
(?=.*\d)(?=.*[A-Z])(?=.*[a-z])
|
(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])
|
(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])
|
(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9])
)^.*
Which simplifies down to something like:
^(
(?=.*[A-Z])(?=.*[\W_])(?=.*[a-z\d])
|
(?=.*[a-z])(?=.*\d)(?=.*([A-Z\W_]))
).{8,255}$
Is this what you intended? I see where you're going with the password rules, but it may be easier to just simplify them and require one capital, one lowercase, one number, and one special character. You could also try to get validation working with a simpler regex pattern, and then add complexity once everything else is working.
Try to use RegularExpressionValidator.ErrorMessage instead of Text.
Try restarting VS. Sometimes incredible bugs disappear after that.
Try removing and regenerating your ..aspx.designer.cs file (to
regenerate right click the aspx/ascx file and choose "convert to web
application").
Agree with others, you should indeed check your resource file.

Categories