.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
SP
satyapriyanayak
Subhransu Sekhar Jena
abhays
DotnetUser
Post New Web Links

How do you use javascript to modify asp:textbox attributes? (set autopostback)

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net
 

If you have this item in the aspx page:

<asp:TextBox ID="Slider1" runat="server" OnTextChanged="Slider1_TextChanged" AutoPostBack="True"  >


how do you write a javascript function to set AutoPostBack="False" and to OnTextChanged to something else?


any examples please? please show me with some code.


thanks






View Complete Post


More Related Resource Links

Modify Javascript via .Net?

  

Hi

I have an ASP.NET page which has some Javascript in it.

Is there a way in the Code Behind to modify the Javascript?

Say for example I have an Array in my Code Behind with 10 values (24, 17, 36, 47.....)

How would I make the Javascript become ....

<script type="text/javascript">

    //<![CDATA[

    function load() {
    if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    //map.setCenter(new GLatLng(37.4419, -122.1419), 1);
    map.addControl(new GLargeMapControl());
    map.setCenter(point, 1);
var point = new GLatLng(-33.9417, 24); var marker = new GMarker(point); map.addOverlay(marker); point = new GLatLng(-33.9427, 17); marker = new GMarker(point); map.addOverlay(marker); point = new GLatLng(-33.9437, 36); marker = new GMarker(point); map.addOverlay(marker);
    point = new GLatLng(-33.9437, 47);
    marker = new GMarker(point);
    map.addOverlay(marker);
} } //]]> </script>


 


Issues with multiline textbox, javascript and IE

  

Hi All,

i have a requirement to embolden/italicise the selected  text in a textbox. the way it is implemented as is by using a js function which inserts <b> and </b> tags at the start and end of the selected text  for bold, and similarly <i> and </i> tags at the start and end of the selected text  for italics.

here is the code in c# (to add attributes to link buttons)

lkbBold.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'B'); return false;");
lkbItalic.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'I'); return false;");


the txtTitle is the id of the text box, which contains the selected text to be emboldend.

and here's the javascript method

function AddHTMLTags(textBoxId, format)
{
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  var textToReplace; 
  
  var content = document.getElementById(textBoxId).value;
  var content1 ;
  var content2 ;
  var newContent; 
    
      // For IE 
      if (document.selection != undefined)
      {
        textComponent.focus();
       
        var len =  document.selection.createRange().text.length;
        var myrange

Javascript to update value in Textbox

  
Hi I have a javascript file, which creates a calendar picker. This file is used through out the application and is a piece of code that I have to use because my .Net application is part of another application which uses this piece of JavaScript code.Anyhow, with the calendar picker I can save the date into a textbox, but the problem that I have is the format. Unfortunately, I cannot change the calendar picker code because this will affect other parts of the application. Therefore, what I am looking to do is to reformat the date on the textbox control. This I can do but only when I use the javascript event onfocus.Now, my question is this, is there away in javascript or with jquery that when a value enters into a textbox that this value is then reformatted to the format I want without postback or clicking on the textbox?Thanks

Problem with JavaScript on Textbox

  
 I have a textbox which is populated by an external javascript file which I cannot alter without affecting another part of the system. What I would like to do is once this textbox has a value to do something with it. The javascript that I want to use is fine, but it won't automatically when a value has populated it i.e. onchange. It will work when the event is onfocus. Is there away in which I can automatically fire off my javascript event when a value has entered the textbox from another piece of javascript code?  

problem with javascript in multiline textbox

  
 I am setting Maxlength of a textbox using javascript. Take maxlegth as 100.As we know Enter key is taking two char space. But i want to avoid this. i.e. if i press enter key after 96th char it should allow me to enter four more char where now it is allowing only 98. This is wat i am using  function textboxMultilineMaxNumber(txt,maxLen) { try { if(txt.value.length > (maxLen-1)) return false; } } catch(e){ } }

linebreak in textbox using javascript

  
I want to assign a textvalue with linebreaks to a textbox control using javascript.I tried (\n):hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}\n\n\n#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")and tried (<br/>)hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}<br/><br/><br/><br/>#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")But without luck....How to do it?

modify/override properties of default sharepoint modal dialogs (ex. editview.aspx) using javascript

  
Hello all, I would like to know how can I modify (override) some properties of the default sharepoint modal dialogs using Javascript. Ex. the size and location of editview.aspx. I while ago I asked a question about overriding the DialogResult in the display view dialog. I got an answer from Zach which looked like this:             sb.Append("<script type=\"text/javascript\">");             sb.Append(@"window.setTimeout(function () {");             sb.Append(@"if (window.frameElement && typeof(window.frameElement.overrideDialogResult) == 'function')");             sb.Append(@"{");             sb.Append(@"SP.SOD.executeFunc('sp.ui.dialog.js', 'SP.UI.DialogResult.OK', function () {");             sb.Append(@"window.frameElement.overrideDialogResult(SP.UI.DialogResult.OK); ");             sb.Append(@"});");             sb.Append(@"}");  

Updating gridview attributes from javascript

  
Hello,   I have been trying to use a custom attribute in my gridview to pass a comma delimited list of guids between my server-side and client side code.  Normally I would just use a hidden-field to do this, but I have to add a hidden-field into a row in my gridview to use one.  Since I need access to the updated value from javascript before my grid is rendered on postback, I can't use a control that is buried inside a row.  So instead, i was trying to add an attribute to the gridview and having the javascript update that value.   Here is the private property defined in my extended gridview class:  private List<Guid> _selectedValues { get { List<Guid> myList = new List<Guid>(); if (this.SelectionType != SOMgridviewSelectionType.None) { if (ViewState["SelectedValues"] != null) { return (List<Guid>)ViewState["SelectedValues"]; } } return myList; } set { if (this.SelectionType != SOMgridviewSelectionType.None) { if (string.IsNullOrEmpty(this.Attributes["hiddenSelectedValues&q

javascript for field validation on a textbox...

  
I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

Weird behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender

  
I ran in to some strange behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender. This gridview is in an updatepanel with scriptmanager. When my gridview is filled with data, it keeps running my OnTextChanged  function and therefor makes my application terribly slow. I need to have the autopostback and ontextchanged function to recalculate stuff in my gridview. Does anybody know of this problem and if so does anybody found a workarround ?

Not able to bind textbox with javascript textbox? Why?

  
I'm trying to use a javascript Date and Time calendar in my Insert and Edit templates in a Detailsview that is bound to SQL Fields. The reason I am trying the javascript date time selector is that I need to have the date and time, the asp.net one is just the date part. I guess my first question is this possible? I tried using it with an asp:textbox on just a plain aspx page and it works like a charm, however when I add it to the detailsview i keep on getting the "Error: Object required"  am I missing a step here?  That and seeing as I'm using a site master page where exactly do I put the:  "<script type="text/javascript" src="datetimepicker_css.js"></script> "   <asp:TemplateField HeaderText="Start Time" SortExpression="StartTS"> <EditItemTemplate>   <asp:TextBox ID="STEditCalendartxt" runat="server" Text='<%# Bind("StartTS") %>'>    </asp:TextBox> <a href="javascript:NewCssCal('STEditCalendartxt','mmddyyyy','arrow',true)"> <img src="images/cal.gif" width="16" height="16" alt="Pick a date"></a>  </EditItemTemplate> Any assistance would be greatly welcomed.

Disable copy paste in textbox without Javascript

  

Hi,

 

Can you somebody help me in disabling copy paste in the textbox without using Javascript for an web application?

 

Regards,

Jeeva.


TextBox AutoPostBack not working when handling other DHTML event

  

I have to format a number in a TextBox while it is being typed. Right after the TextBox looses focus, I need to do other processing on server side, including some database queries.

I'm doing the formatting by handling the onkeyup event, client side. But when I add the handler, the onTextChanged event stops firing on the server. I've tried different return values for the handler but unfortunatelly I'm stuck.

To reproduce the problem, here is a sample where the formatting function was replaced by a simple "convert to uppercase" function. You'll see that, contrary to the expected, the Label doesn't get filled when the TextBox looses focus. It does get filled, however, if the user presses the ENTER key.

What can I possibly be doing wrong with such a simple task?

 

<%@ Page Language="VB" %>

<script language="VB" runat="server">

Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

'' Adding the event handler like this has the same effect as adding it inline

'txtTextBox.Attributes.Add("onkeyup", "return(upperCase(this));")

End Sub

Protected Sub txtTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)

lblTextBox.Text = S

How do you get a textbox/input or a javascript to postback?

  

I am using a Yahoo UI dual slider.  The dual slider changes values based on what you slide.  It uses javascript and sends this value back to a Input type="text" textbox. 


I want to be able to do a automatic postback and call the server function "protected void zoom(object sender, EventArgs e)"  each time the slider value changes.

So what I did was:

<asp:TextBox type="text" id="demo_from"  runat="server"
OnTextChanged="Zoom" AutoPostBack="true">

But the problem is, it WILL not fire the server-side event unless I manually click the textbox and press "ENTER".  Then the event will fire (during debug).


So how can I get the event to auto-fire each time the slider value changes?


thanks!




Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend