This sounds ridiculously simple but I can't find anything that will act like Access' AfterUpdate event. What I want to do is to is this:
User enters a Group Number
After Update (tabbing off, clicking into a new field, clicking a button, whatever...), query my table for the Group Name and place it in
the circle marked "2"
Also fill in additional info based on the Group Number
I understand that I can just put in something like a button called "Validation" and then perform #'s 2 and 3, but the users don't want the extra button click. In Access, this could easily be performed with an AfterUpdate event, so how would I do this with C#?
Server side:
Set AutoPostBack="True" for your TextBox and handle TextChanged event in your code.
<asp:TextBox ID="groupTextBox"
runat="server"
AutoPostBack="true"
OnTextChanged="groupTextBox_TextChanged">
</asp:TextBox>
Client Side:
To handle it at client side you can use Javascript like:
<asp:TextBox ID="groupTextBox2"
runat="server"
OnBlur="YourJavaScriptMethod();">
</asp:TextBox>
and in your method in Javascript could be:
function YourJavaScriptMethod()
{
alert(document.getElementById('<%= groupTextBox2.ClientID %>').value);
}
You can send a AJAX request to get data based on the text changed.
Related
I am using an aspx page, single file web form, to capture user input on the client side via a dropdown box and then modify available text box fields (simple example...if client selects dropbox item 1, then text box 1 is enabled; if client selects dropbox item 2, then text box 2 is enabled).
The dropbox html code looks like this and works perfectly with exception of event handler OnSelectedIndexChanged:
<asp:DropDownList ID="FAQ" runat="server" ViewStateMode="Enabled" EnableViewState="true" Width="354px" AutoPostBack="true" OnSelectedIndexChanged="selectedFAQ()" >
<asp:ListItem Text="Please Select" Value="Default"></asp:ListItem>
<asp:ListItem Text="Text 1 Here" Value="FAQ1"></asp:ListItem>
<asp:ListItem Text="Text 2 Here" Value="FAQ2"></asp:ListItem>
<asp:ListItem Text="Text 3 Here" Value="FAQ3"></asp:ListItem>
</asp:DropDownList>
The function selectedFAQ() is defined in the script section:
function selectedFAQ()
{
//code to enable/disable text fields here
}
I have seen several different posts and answers to this issue, but it seems that the posts I have seen contained an aspx and aspx.cs file...my page is the single web form.
I also want to mention that the page is not my creation, I am simply trying to add additional functionality to it. And finally, there is a "inherits" tag that references a 3 year old dll that I do not have the code for.
If this issue has been addressed, please point me to the correct question/answer and thanks. If not, please assist if able. I can provide any additional code if needed. Thanks.
What you currently have is a subscription to a postback event. That is, function that should handle change of index in server side code. However your fucntion is actually a javascript one and executes on a client side. To call that, you need to assign a different attribute of the drop down control:
onchange="selectedFAQ();"
And remove handling of OnSelectedIndexChanged, you won't be able to define a server side handler without code behind access anyway.
I have been having trouble updating the value for my input type=text or the texbox control text value with the jquery $(window).resize(function(){}); I know that the event fires because when i resize the browser an alert will appear. I also am using the functionality for something else.
It currently looks like this:
$(window).resize(function(){
if($(window).width()>1080){
var innerwidth = $(window).width()-170;
$("#div1").width(innerwidth);
}
I want to add this:
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('input.hiddentest').val(innerheight);
}
I know that the issue lies with:
$('input.hiddentest').val(innerheight);
I have also tried this:
$('#texttest.ClientID').text(innerheight);
This is the input and the textbox below that I am using(note that the type used to be hidden, but i dont think that makes an issue and I wanted it to be visible for debugging purposes)
<input id="hiddentest" type="text" visible="true" name="hiddentest" onclick="test();" runat="server" value="1000" />
<asp:TextBox id="texttest" Visible="true" runat="server" Text="1000" />
Overall I have been looking for a way to dynamically update the values as the page resizes with the size of the page. My geuss is that i am not using the right thing to identify the id's. Thanks for taking the time to look at this and for any replies.
P.S. I am also open to the idea of using a javascript function instead but i can't even seem to get the function to fire for the resize event so it would require more help.
This is what i have so far:
window.onresize=Test();
function Test(){
var hdnfld= document.getElementById("texttest");
var testing = window.innerWidth;
alert(testing);
hdnfld.text= testing;
}
Use just ID of elements without dots (that actually represent the classes you don't have).
So use
$('#hiddentest').val(innerheight)
and
$('#texttest').val(innerheight)
Note that asp:TextBox renders as inptut type="text" so you still have to use .val() on it, not .text()
Hidden text box id is "hiddentest" so the code will be
$('#hiddentest').val(innerheight);
hiddentest is an id not a class in your case
Try,
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('#hiddentest').val(innerheight);
}
});
<asp:TextBox id="texttest" Visible="true" runat="server" Text="1000" />
For the above asp.net textbox control, the ID changes dynamically when rendered (prepended with master and page information), id looks similar to main_ctrl100_texttest
var hdnfld= document.getElementById("texttest");, so this no longer holds good. Use a class instead.
<asp:TextBox id="texttest" Visible="true" runat="server" CssClass="texttest" Text="1000" />
var hdnfld = document.getElementsByClassName("texttest");
If you need more info on how to access .net controls using jquery, see here.
Very new to ASP.Net development so hope this is not too much of a silly question.
I have a web page (framework 3.5) with a DetailsView control which is bound to sql and reads records via a Stored Procedure. AllowPaging = true on the control because more than one record may be found.
It uses a text box control - value entered by the user - to pass to the SP.
The text box has a Regular expression validation control which highlights when input is invalid.
I am doing as follows:
enter valid data in text box and hit 'enter' - records are found so DetailsView shows me the first record plus numbered paging buttons (correct)
change the value in the textbox to something invalid, and tab out of textbox - validation control highlights the error (correct)
press 'enter' - nothing happens, invalid (correct)
click on one of the numbered paging buttons in the DetailsView - postback occurs. The validation control has not prevented the paging taking place. I would like to prevent any postback/response other than forcing the user to correct the invalid data in the text box.
Am sure there should be an easy way to handle this and have tried various options but not getting there.
Thanks in advance.
Basically here validation doesn't happens when you click on any numbered paging buttons of DetailsView.
Preventing even complete postback requires that page checks for Client side validation. Also
to make the validation occur on server side,call Page.Validate() in PageIndexChanging event of DetailsView. If the page is Not valid prevent the paging from happening.
NOTE I: You can call Page.Validate() inside Page_Load event also. It's not necessary that you should call this event in DetailsView.PageIndexChanging event only.
NOTE II: in case you just want only to prevent paging to occur and don't want to use PagerTemplates, use server side validation. A postback will always happen, although if Page is not Valid, Paging will not occur.
Start by using <PagerTemplates> for paging in DetailsView and set the CausesValidation attribute to true for the pager buttons. The below settings of CommandName & CommandArgument will automatically take care of your Paging. See MSDN.
<pagertemplate>
<asp:LinkButton id="PreviousButton"
text=" Previous_"
CommandName="Page"
CommandArgument="Prev" CausesValidation="true"
runat="Server"/>
<asp:LinkButton id="NextButton"
text="Next_"
CommandName="Page"
CommandArgument="Next" CausesValidation="true"
runat="Server"/>
</pagertemplate>
Markup of DetailsView:
<asp:DetailsView runat="server" ID="EmpDetails"
OnPageIndexChanging="EmpDetails_PageIndexChanging" ... />
Event Handler
protected void EmpDetails_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
Page.Validate();
if (!Page.IsValid)
e.Cancel = true;// Prevent the paging
}
Google Chrome and FireFox browsers have a feature that allows users to save user name and passwords to their local machine. This allows them to login the next time without much effort or remembering what that information is. The information is basically auto-filled. When those browsers do this it shows the * in the textbox. Showing that the browser successfully placed the value in the RadTextBox. However, when the c# code behind retrieves the value as an empty string.
My code is as follows
<telerik:RadTextBox ID="txtPassword" runat="server" ToolTip="Enter password"
Text="" MaxLength="40" EnableSingleInputRendering="False"
Wrap="False" TextMode="Password" CausesValidation="false" Skin="WebBlue">
</telerik:RadTextBox>
Code Behind:
objLogin.Password = txtPassword.Text;
Even odder is the fact that if you click the button more than once it will then the code behind will see the actual value and proceed to log you in. It seems that the RadTextBox Control needs to be rendered a second time or post back is required for the control to work properly.
What do I need to do to get the RadTextBox control to recognize the inputed value from the browser initially without having to click multiple times for the code behind to see the value?
Thanks for your help.
That is because your textboxes gets the value on the client side alone, while the underlying RadTextBoxes values do not.
I have experienced this issue before where values set to a RadTextBox by using jQuery xxx.val('...') do not get through to the server-side on postback.
The only way to get the value 'assigned' to the RadTextBox control's Text property from client-side is to use:
$find('<%= txtUsername.ClientID%>').set_value('newvalue');
In your case, most probably the browsers set (autofill) the values and only available on client side. Therefore, what you can do to actually assign those values is to intercept before the Login button postbacks, like so:
var un = $('#<%= txtUsername.ClientID%>').val();
var pw = $('#<%= txtPassword.ClientID%>').val();
$find('<%= txtUsername.ClientID%>').set_value(un);
$find('<%= txtPassword.ClientID%>').set_value(pw);
If you are using RadButton as the Login button, this can be done on the button's OnClientClicking/OnClientClicked event like so:
<telerik:RadButton ID="cmdSignin" runat="server" Text="Sign In"
SingleClick="true" SingleClickText="Signing In..."
OnClientClicking="OnClientClicking"></telerik:RadButton>
Hope that helps.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Lost Focus method for asp.net textbox?
i want to check the data entered by user on the client side.
it is necessary for me to use control.
is there any way so that i can check after client move on to the next input and i can check the data by javascript ?
<asp:TextBox ClientIDMode="Static" onblur="return userCheck(this.id)" onkeyup="return userCheck(this.id)"
ID="txtUserName" runat="server" Width="180"></asp:TextBox>
here i have used two events but i want to use only one.
You can do that with onblur event using javascript.
f.e something like that:
<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />
For what you want to do, you can set the textbox to have AutoPostBack=True; any time the text in the box is changed and the box loses focus, it will post back to the page; you can use the TextChanged property, as well, if you don't want to post back, which will check to see if the text of the TextBox has been changed between posts.
Finally, you can bind the JavaScript onFocus and onBlur events to the textbox, and handle changes to its contents via JavaScript:
http://support.microsoft.com/default.asp…
Source: http://answers.yahoo.com/question/index?qid=1006040618831