Hi I have created a jquery script, that makes a textbox as autoCompletebox, and it's working very well.
For this script to work, I want to get the Value HiddenField ClientID in jqvalue and OnSelect trigger button in jqbutton.
<asp:HiddenField ID="vendorIDField" runat="server" />
<asp:TextBox ID="TextBox1" runat="server" CssClass="jq-autocbox absfields" pos="c3 r2" igaddl="nofield" jqvalue = "#<%= vendorIDField.ClientID %>" jqcontainer = ".form-content" jqURL = "GetLists.ashx" jqcommand = "GetVendors" jqbutton = '#<%= Button2.ClientID %>' Width="250px" ></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" />
But the ClientID is not compiling. In browser it appears like what I type inside single quotes.
You can assign the value to attribute in code behind using Attributes collection.
TextBox1.Attribute["jqvalue"] = vendorIDField.ClientID;
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 am using the ASP.net framework. I am building a web form using the design view of the .aspx file. I have made a very simple form, the below is the code in the .aspx file.
<asp:TextBox ID="TextBox3" runat="server" Height="60px" Width="550px" TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Height="60px" Text="Button" Width="100px"/>
<asp:Button ID="Button2" runat="server" Height="60px" Text="Button" Width="100px" />
The problem is that when I set the TextMode to MultiLine the position of buttons changes too.
Textmode set to single line:
Textmode set to multi line:
Any explanation for this?
I have a formview, connected to an objectDataSource.
It's a pretty easy code in the "EditItemTemplate" of the formview, implemented in the .aspx class:
<EditItemTemplate>
Var1: <asp:TextBox ID="txtVar1" runat="server" Text='<%# Bind("var1") %>' />
Var2: <asp:TextBox ID="txtVar2" runat="server" Text='<%# Bind("var2") %>' />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="ButtonSave_Click" />
</EditItemTemplate>
When pressing "save" the data of "var1" and "var2" passes with the object to the next update method, that is implemented in the business logic class:
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
public void UpdateMyObject(MyObject updatedObject)
{
if (updatedObject.EntityState == EntityState.Detached)
mContext.MyObjects.Attach(updatedObject);
mContext.ObjectStateManager.ChangeObjectState(updatedObject, System.Data.EntityState.Modified);
int numberOfAffectedRows = mContext.SaveChanges();
if (numberOfAffectedRows == 0)
throw new DataNotUpdatedException("No object updated!");
}
The thing is that I need to pass a 3rd variable from the aspx to the business logic, without exposing it to the user through a textbox. It's a Guid and there is no need to change it.
With the current code, the Guid that is assigned to the "updatedObject" is only zeros and not the original Guid of the object, that it has and would have passed if I had binded it to a textbox, using a <%# Bind("entryGuid") %>.
So, my question is how can I pass this Guid (or any other variable) to the business logic layer, without the need to expose it? Is there an elegant way to bind data to the updated object not through a textbox?
Thanks!
Since #tzerb's answer left out an example, I thought I'd provide one.
<EditItemTemplate>
Var1: <asp:TextBox ID="txtVar1" runat="server" Text='<%# Bind("var1") %>' />
Var2: <asp:TextBox ID="txtVar2" runat="server" Text='<%# Bind("var2") %>' />
Var3: <asp:HiddenField id="hdnVar3" runat="server" Value='<%# Bind("var3") %>' />
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="ButtonSave_Click" />
</EditItemTemplate>
I think you're looking for
input type="hidden"
This will hide the input from the users and will be available in the post back. The users will be able to see it if they 'view code'.
I want to disable the button that is contained in a data list row. Is it possible to disable the button after it has been clicked once by the user? If so, can someone please suggest how I can achieve that.
<asp:DataList ID="DataList1" runat="server" DataKeyField="Qno" OnItemCommand="DataList1_OnItemCommand"
DataSourceID="SqlDataSource1">
<ItemTemplate> <asp:RadioButton ID="RadioButton1" runat="server" Text='<%# Eval("Ans1") %>' GroupName="qu" />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" Text='<%# Eval("Ans2") %>' GroupName="qu" /> <asp:Button ID="Button2" runat="server" Text="Submit" CommandName="Validate" />
<br />
</ItemTemplate>
I have nothing to do with ASP, but if you want javascript (jQuery) solution then you can just do something like
$(.once-clickable-button).click(function(){
$(this).attr("disabled", "disabled");
// if needed - do what it is supposed to do
});
(of course add class "once-clickable-button" to the button or chose the name that suits you)
<script type="text/javascript">
function checkEnableSubmit() {
document.getElementById("Button2").disabled = true;
}
</script>
call this method on the onclick event when u want to disable the button
With javascript you could do something like the following:
document.getElementById("buttonID").disabled = true
Here's my HTML
<asp:UpdatePanel runat="server" ID="panel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:FormView runat="server" ID="formViewUno" DataSourceID="odsBob" DefaultMode="Insert">
<InsertItemTemplate>
<span>Name:</span>
<asp:Literal ID="Literal4" runat="server" Text=" " />
<asp:TextBox runat="server" ID="tbxName" Text='<%# Bind("Name") %>' />
<br />
<span>Age:</span>
<asp:Literal ID="Literal5" runat="server" Text=" " />
<asp:TextBox runat="server" ID="tbxAge" Text='<%# Bind("Age") %>' />
<br />
<span>City:</span>
<asp:Literal ID="Literal6" runat="server" Text=" " />
<asp:TextBox runat="server" ID="tbxCity" Text='<%# Bind("City") %>' />
<br />
<asp:Button ID="Button1" runat="server" CommandName="Insert" Text="Insert" />
</InsertItemTemplate>
</asp:FormView>
<asp:Panel runat="server" ID="msgs">
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Here's my C#
private void odsBob_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
var p = e.ReturnValue as Person;
if (p != null)
{
var msg = new Label
{
Text =
String.Format("{0} [Age:{1}, City:{2}] was successfully added", p.Name, p.Age,
p.City)
};
var br = new LiteralControl { Text = "<br/>" };
msgs.Controls.Add(br);
msgs.Controls.Add(msg);
}
}
How can I persist (add a new one after the insert) the label controls? It is being wiped out. The new one added is added each time correctly. How can I keep the control collection in tact? Thanks for any help.
Cheers,
~ck
It looks like you're dynamically creating a label object during the event handler.
Dynamic controls are problematic because they need to be recreated on every postback. Remember that a postback creates a new instance of your Page object - which means that the controls you added to your last page are gone - your Panel is initialized as empty with each new request, so only the latest literal/label pair will be added.
One solution may be to add all the necessary textual information to Session, and have your Panel generate dynamic labels and literals from whatever is in Session during Prerender.
Another solution would be more complex, but you could have the Panel add labels and literals dynamically during the Init phase. If you can ensure that the same number of controls is added in the same order during Init, then the ViewState for those controls will be properly tracked on each PostBack. You would basically need to store the most recently added label and literal into Session, and have the Panel fetch it out on the next request to ensure it got added back in during Init. You'd also need to store a counter so that the Panel knew how many sets of controls to add during Init.