I have a strange problem, but I can't get a solution:
We use the Infragistics WebDataGrid, in which I set a dropdown and a textbox.
For both of them I set a requiredfieldvalidator:
<asp:RequiredFieldValidator ValidationGroup="attrib" runat="server" ControlToValidate="ddlIndRoleAttribType" ToolTip="Attribute Type is not set." InitialValue="-- not selected --" Text="!" Display="Dynamic" />
</div>
</ItemTemplate>
</ig:TemplateDataField>
<ig:TemplateDataField Header-Text="Value" Key="IndRoleAttribVal" Width="50%">
<ItemTemplate>
<div>
<stgwc:TextEdit runat="server" Width="300px" ID="txtIndRoleAttribValue" />
<asp:RequiredFieldValidator ValidationGroup="attrib" runat="server" ControlToValidate="txtIndRoleAttribValue" Width="90%" ToolTip="Attribute Value is not set." Text="!" Display="Dynamic" />
</div>
</ItemTemplate>
</ig:TemplateDataField>
<ig:TemplateDataField Header-Text="Action" Key="IndRoleAttribAction" Width="40px">
<HeaderTemplate>
<stgwc:ImageLinkButton runat="server" ID="btnCreateNewAttribute" CausesValidation="false" ImageUrl="~/Images/base/Icons/16x16/add2.png"
ToolTip="Add new Attribute" CommandName="Create" />
<stgwc:ImageLinkButton runat="server" ID="btnSaveAllAttributes" ValidationGroup="attrib" ImageUrl="~/Images/base/Icons/16x16/disk_green.png"
ToolTip="Save all Attributes" CommandName="Save" />
<stgwc:ImageLinkButton runat="server" ID="btnCancelChanges" CausesValidation="false" ImageUrl="~/Images/base/Icons/16x16/undo.png"
CommandName="Cancel" ToolTip="Discard changes" />
</HeaderTemplate>
<ItemTemplate>
<stgwc:ImageLinkButton runat="server" ID="btnDeleteAttribute" CausesValidation="false" ImageUrl="~/Images/base/Icons/16x16/delete2.png"
ToolTip="Delete this Attribute" CommandName="Delete" CommandArgument='<%# Bind("IR_ATTR_ID") %>' />
</ItemTemplate>
</ig:TemplateDataField>
</Columns>
</stgwc:WebDataGrid>
I do a postback if a new item should be created, then I set it to the datasource and reload it, something like this:
dgrIndRoleAttributes.ClearDataSource();
dgrIndRoleAttributes.Rows.Clear();
dgrIndRoleAttributes.DataSource = null;
dgrIndRoleAttributes.DataSource =
(Session[Constants.Session.RoleAttributes.ToString()] as List<TmpIndRoleAttribute>);
dgrIndRoleAttributes.DataBind();
Now comes the funny part: When I press enter after adding a new row, Firefox (only Firefox, on IE it works proper), seems to think the validators on the validator-group attrib arent set proper and I need to click twice, to make it save.
If I check this with the firebug, I see both validators being on display: none, so this cant be problem. As said, this happens only on Firefox, and I cant reproduce it on a small testsample.
Has anyone a idea, what could cause this behavior? Since I'm not used to this validators, I can't imagine, what could cause this problems.
Thanks for you response!
Matthias
Edith says: It's a infragistics bug... Another one... I use in this case the normal asp textbox and change the style with some css.
Related
.aspx
<asp:TextBox ID="txtInvite" Width="170px" Height="20px" runat="server"
Font-Size="Small" ></asp:TextBox>
<AjaxToolkit:TextBoxWatermarkExtender ID="tbexInvite"
runat="server" SkinID="skinTextBoxWatermarkExtender"
TargetControlID="txtInvite" WatermarkText="Email"></AjaxToolkit:TextBoxWatermarkExtender>
<asp:RequiredFieldValidator ID="rfvInvite" runat="server"
Display="None" ValidationGroup="Inivitation" SetFocusOnError="true"
ControlToValidate="txtInvite" ErrorMessage="Enter Email."></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="regExpInvite" runat="server"
Display="None" ValidationGroup="Inivitation" SetFocusOnError="true"
ValidationExpression="\s*\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*\s*"
ControlToValidate="txtInvite" ErrorMessage="Invalid Email Format."></asp:RegularExpressionValidator>
<div class="ButtonLogin" style="margin-top:-27px;margin-right:143px;_margin-right:105px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite" ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true" onclick="btnInvite_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0">
<ProgressTemplate>
<asp:Image ID="Image1" ImageUrl="~/App_Themes/Lifetrons/images/progressbar.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
Page_load Code
.CS
this.btnInvite.Attributes.Add("onclick", "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(this.btnInvite, "").ToString());
I want to disable button after clicking on it with maintaining validation and Onlick method. I refer to this question my problem is same like this question but I haven't solve my problem. How can I solve?
There is no need to mess around with your code-behind Page_Load event. In your button control, just add the following snippet:
OnClientClick="if(Page_ClientValidate('Inivitation')){this.disabled=true;}"
So that your button looks like
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite"
ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true"
onclick="btnInvite_Click" OnClientClick="if(Page_ClientValidate('Inivitation')){this.disabled=true;}" />
You should be able to disable the button using the Button_Click method. Make your first line something like this:
Button.Enabled = False;
There is a problem with this method though. If the page loads too quickly or the code freezes it will not disable the button properly. Just remember to re-enable the button at the end of the method if the validation fails or times out.
Another method you may try is to hide it using CSS. I am a big fan of this because it always works and it is very simple. You need a technology like jQuery where you can add classes on the fly. You can use the AddClass and RemoveClass API in jQuery to add/remove CSS classes at runtime. Take a look here. http://jqueryui.com/addClass/
you can use Like this
<asp:Button ID="btnInvite" runat="server" CssClass="cssLoginButton blue" Text="Invite" ToolTip="Invite" ValidationGroup="Inivitation" CausesValidation="true" UseSubmitBehavior = False"onclick="btnInvite_Click" />
I have a FormView (with paging enabled) that is bound to a LinqDataSource on an ASP.NET page. I'm experiencing some very weird behavior and can't figure out why it's happening. For simplicity sake on this question I have removed some unneeded code (other FormView templates, etc) to demonstrate this behavior.
My FormView has 3 fields, two textboxes and one DropDownList. The DropDownList is bound to another LinqDataSource on the page and contains foreign key values. When the FormView's LinqDataSource only contains one record and I try to update it, the update fails because the selected value of the DropDownList is always empty, no matter which value I pick for it. When the FormView's LinqDataSource contains 2 or more records, it works as it should.
Now here's the really weird thing. The update is actually failing because of the FormView's PagerSettings! When I use just the default Pager settings, all is well. When I change the PagerMode to NextPreviousFirstLast, the update fails.
Here's my FormView with it's data sources:
<asp:FormView ID="fvData" runat="server" AllowPaging="True"
DataKeyNames="ID" DataSourceID="ldsData" DefaultMode="Edit">
<EditItemTemplate>
<table class="pad5">
<tr>
<td class="field-name">AREA:</td>
<td>
<asp:DropDownList ID="cboAREA" runat="server" DataTextField="AREA_NAME"
DataValueField="AREA1" SelectedValue='<%# Bind("AREA") %>' DataSourceID="ldsAreas" />
</td>
</tr>
<tr>
<td class="field-name">LOOP:</td>
<td><asp:TextBox ID="txtLOOP" runat="server" Text='<%# Bind("LOOP") %>' /></td>
</tr>
<tr>
<td class="field-name">LOOP DESCRIPTION:</td>
<td><asp:TextBox ID="txtLOOP_DESCRIPTION" runat="server"
Text='<%# Bind("LOOP_DESCRIPTION") %>' style="width: 600px" /></td>
</tr>
</table>
<asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" CausesValidation="True" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="False" />
</EditItemTemplate>
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="<< First" LastPageText="Last >>"
NextPageText="Next >" PreviousPageText="< Prev"
Position="TopAndBottom" />
<PagerStyle CssClass="pager" />
</asp:FormView>
<asp:LinqDataSource ID="ldsData" runat="server"
ContextTypeName="E_and_I.EAndIDataDataContext" EnableDelete="True"
EnableInsert="True" EnableUpdate="True" EntityTypeName=""
TableName="INSTRUMENT_LOOP_DESCRIPTIONs" onselecting="ldsData_Selecting" OrderBy="ID ASC" >
</asp:LinqDataSource>
<asp:LinqDataSource ID="ldsAreas" runat="server"
ContextTypeName="E_and_I.EAndIDataDataContext" EntityTypeName=""
TableName="AREAs" onselecting="ldsAreas_Selecting">
</asp:LinqDataSource>
And here's both of my LinqDataSource's Selecting events:
EAndIDataDataContext db = new EAndIDataDataContext();
protected void ldsData_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = db.INSTRUMENT_LOOP_DESCRIPTIONs.Take(1); // we only want one record for testing
}
protected void ldsAreas_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
e.Result = db.AREAs.OrderBy(a => a.AREA1).Select(a => new { AREA1 = a.AREA1, AREA_NAME = "(" + a.AREA1 + ") " + a.AREA_NAME });
}
I've traced the problem to these lines:
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="<< First" LastPageText="Last >>"
NextPageText="Next >" PreviousPageText="< Prev"
Position="TopAndBottom" />
As soon as I remove the above PagerSettings element, the FormView updates the record just fine! Does anybody know why the hell the pager settings would have anything to do with this? I'm using the .NET Framework 4.0.
I copied part of your code and I made an experiment and I think, I'm experimenting the same behavior.
This is what I did:
<asp:LinqDataSource runat="server" ID="lds"
TableName="jobs" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" >
</asp:LinqDataSource>
<asp:LinqDataSource runat="server" ID="ldse"
TableName="employee" ContextTypeName="WebApplication2.DataAccess.PubsDataContext" OnSelecting="ldse_Selecting">
</asp:LinqDataSource>
<asp:FormView runat="server" DefaultMode="Edit" ClientIDMode="Predictable" DataKeyNames="emp_id" DataSourceID="ldse"
AllowPaging="true" OnItemCommand="Unnamed_ItemCommand" ID="formView">
<EditItemTemplate>
<div>
<asp:DropDownList runat="server" ID="ddlJobs" DataSourceID="lds" DataTextField="job_desc" DataValueField="job_id">
</asp:DropDownList>
</div>
<div>
<asp:TextBox runat="server" TextMode="MultiLine" ID="txtDesc" />
</div>
<div>
<asp:Button Text="Save" runat="server" CommandName="Save" CausesValidation="true" />
<asp:Button Text="Cancel" runat="server" CommandName="Cancel" CausesValidation="false" />
</div>
</EditItemTemplate>
<PagerSettings Mode="NextPreviousFirstLast"
FirstPageText="<< First" LastPageText="Last >>"
NextPageText="Next >" PreviousPageText="< Prev"
Position="TopAndBottom" />
These are my observations:
If the FormView contains only one row, then the FormView behaves weird and my commands do not work as expected.
My Save command is never fired, instead the `Cancel command is fired
My Cancel command causes my FormView to disappear...
First I thought this was because of the & characters, but this is not the case
I narrowed the problem to Position="TopAndBottom"
If you set the Position attribute to:
Top
TopAndBottom
You will experiment the same problem. (As you mention probably a bug)
If you set the Position attribute to:
Buttom
It works as expected
To be honest, if this is a bug, I can't believe none else has found it and report it.
I made the same experiment with Visual Studio 2012 for Web (ASP.NET 4.5) and I'm experimenting the exact same behavior...
This makes me think that probably I'm doing something fundamentally wrong and perhaps this is not a bug and that's why I'm experimenting the same behavior with both versions ASP.NET 4 and ASP.NET 4.5, but if that's the case, I simply can't figure out what is it.
On the other hand, if this is a bug, the same bug will be present in ASP.NET 4.5
Edit 1
I uploaded the code to my GitHub site for reference
It's most likely due to the url decoding of the & < and >.
Try taking out the &';' and just use the & symbol. You are able to inject using that method.
I need to get a label during runtime so that i can compare to the Session["userName"] and choose to show buttons after the comparison.
I have look around and this seems to be the solution but i've run onto trouble as i only get null during runtime.
UserName:
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
<br />
So, this is the label inside a "ListView1" i need what Eval finds during each iteration of pumping out of the attached database.
<% Label lbl = (Label) ListView1.FindControl("userName");
string userName = lbl.Text;
if (Session["userName"].ToString() == userName)
{%>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<% }%>
and this is my attempt at retrieving the label.Text. i know it is something similar to this but i might be doing it wrong... well i am doing it wrong.
Thanks you very much for any information you can provide as i have just spent about 10 hours changing the ways i could achieve this result.
I would do something like:
Visible='<%# Session["userName"].ToString() == Eval("UserName").ToString() %>'
on each of the Button controls.
I currently pass some values over to one of my ascx.cs files, and it displays certain radio buttons depending on the value that is sent over. The radio buttons are instantiated in the .ascx side of things:
<asp:RadioButton ID="length5yr" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="Label5yr" Visible="false" style="width: 300px">
</asp:label>
<asp:RadioButton ID="length3yr" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="Label3yr" Visible="false" style="width: 300px">
</asp:label>
<asp:RadioButton ID="length2yr" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="Labelyr2" Visible="false" style="width: 300px">
</asp:label>
<asp:RadioButton ID="length1yr" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="Label1yr" Visible="false" style="width: 300px">
</asp:label>
<asp:RadioButton ID="lengthQuarterly" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="labelQuarterly" Visible="false" style="width: 300px">
</asp:label>
<asp:RadioButton ID="lengthMonthly" GroupName="SubLength" runat="server" Visible ="false"
/>
<asp:label runat="server" id="labelMonthly" Visible="false" style="width: 300px">
</asp:label>
I want whichever radio button that ends up being the first/top one displayed to be checked. I've been able to get the last radio button checked (which also gives me other problems anyways) - but how can I get that top one checked!?
This is the code for how I determine which radio button is displayed - I have only shown one of the options just to make the code a little bit easier to read.
foreach (Dictionary<string, string> d in orderOptions)
{
if (d["length"] == "one")
{
length1yr.Visible = true;
price1yr = d["price"];
rate1yr = d["rate"];
issues1yr = d["issues"];
premium1yr = d["premium"];
Label1yr.Text = d["description"] + "<br><br>";
Label1yr.Visible = true;
SubLength1yr = "1 year";
}
For a server-side solution, the easiest would be to iterate over the list of RadioButton and use some simple LINQ to select the first visible button.
Something like:
var buttons = new []{length5yr, ...};
var firstVisibleButton = buttons.Where(b=>b.Visible).First();
firstVisibleButton.Checked = true;
The above is probably more pseudo-code than anything, but without a full code sample, that's all I can do. I am sure you can figure out the details. The above code would have to execute after you have hidden/shown the RadioButton.
I should probably specify that the list you create (buttons) must follow the order in which the buttons are displayed for this to work properly.
I have a validation summary inside a asp.net formview and the validators just don't seem to trigger the validation summary.
Things I already tried:
Enable the ViewState on everything.
Set the ClientID to static.
Set the ValidationGroup to the same group on both all validators and the summary.
Used Google to search for a solution.
Anyone has any ideas on how to handle this?
Code. Formview declaration:
<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">
Any of the textboxes with the validator:
<td> <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>'
TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
ErrorMessage="Number is Required" ForeColor="Red"
ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
</td>
And the submitbutton:
<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server"
ForeColor="Red" ClientIDMode="Static" CssClass="validation"
ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
/>
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
<asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel" CssClass="ButtonStyle" TabIndex="100"
ValidationGroup="EditPerson" />
Hope the CausesValidation for the button is set to true.
Well, I fixed the issue. If anyone else encounters this problem try the following:
Ensure there is only one (1) validation group on the entire form.
Set "causesvalidation" to "true" on the submitbutton.
Check, double check and triple check the spelling of your validationgroup property on all relevant controls.
Be on the lookout for javascript errors in your client-side scripts. They can cause havoc.