I inherited a legacy app that is a mix of technologies from the last 10 yrs. It is not architected well so please don't berate me on why i need to do this, i just need to do it and get it done...
i have an important variable that is available client side in vbscript
i have an asp.net itemtemplate that lives inside a datagrid
i need to modify the style of a column in the grid based on the client variable
i cannot access the .net stuff in the vbscript to mess with it
i am trying to dynamically add a hidden field via vbscript to the page with the variable that i need, then find that in the .net code maybe using Page.FindControl so I can set the style dynamically using the variable that was given to me client side
any thoughts on the fastest way to do this?
Write the variable to a text file, read the text file into your .Net app.
problem solved, i sent the value in a query string and pulled it out using response.querystring on the .net side
the html tag itself has a .net function embedded in the class tag which will return the right style based on the value. the style hides the field
Related
I am developing a website using mainly AJAX for saving and retrieving data in order to avoid postbacks (or at least full postbacks).
I "prepare" the page in codebehind, and on client I use JQ and Javascript.
When I want to save data I serialize the elements in a container (using JQ) and then AJAX post to send data to the WebMethod.
This is working well but I have to deal with long name elements ("ctl00$MainContent$grdEmployees$ctl03$ddlRole").
Sometimes is difficult to retrive data from the NameValueColletion as the same WebMethod can be called from different pages, so the "name" of the element is not the same as the control may be nested in other container.
Is there a way to set custom names for ASP.NET controls to avoid this issue?
Or other way to achieve this behavior?
Best regards.
Have you tried to use ClientIDMode="Static" which is found in .NET 4.5.
When a page is render the ids all change as you have noted. However, you set the ClientIDMode to static it will render with the ID that you have put for the control itself. That way you can work with the ID of the control instead of the generated id. If you would like to know more here is a like to the MSDNA about ClientIDMode
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode(v=vs.110).aspx
I have an asp website which has a page embeded with swf file.The swf file is build using flex. I want to set a value in a session variable in flex and later use this session variable in asp to retrieve value.
Or is there any method to know changes made in flex(swf file) at asp side.
Note that swf file has a grid in which data change occur.
You can do either of these:
Assign change to a hidden variable in web page.
Query the variable at server side in ASP .Net. And put it in session.
Or
When you want to change any thing in Session, just call the webservice from JavaScript which should change value in Session(or do whatever you want to do in server).
See how you can call ASP.Net WebService from flex.
Does anyone know if it is possible to leverage the power of JQuery on the .Net serverside?
For example I have some HTML as a String in some code behind. Is there a way to execute JQuery on it?
I'm currently doing this...
Assume this is the String...
<input id='AddressSettings_txtFirstName' name='txtFirstName'
value='#firstNameValue#' size='25' type='text' class='val_required'/>
My C# does this
strHTML = strHTML.Replace("#firstNameValue#", customerInfo.FirstName);
And this is how I bind my data to my HTML.
Now what I would like to do is instead of having to add the #firstNameValue# as a place holder and replacing it I would like to somehow execute a line of JQuery on the HTML string in my C# code.
strHTML = strHTML.ExecuteJQuery("$('#AddressSettings_txtFirstName').text('"
+ customerInfo.FirstName + "')");
What are my options here?
For all intents and purposes, the answer is "no" (while there might be some obscure way of handling this, it's not the most optimal way).
It appears you are looking for a way to manipulate the HTML that is being produced on the server-side, which is a very legitimate desire, it's just that the approach on the server side using .NET (or other) technologies is radically different than how you would approach it on the client-side.
Because the content is already rendered on the client, the way you would apprach modifying it is different. On the server, the page is built of from various parts which ultimately render the HTML to the client, using data that the client doesn't necessarily have access to (as well as resources and libraries).
It's for that reason you want to use what's available on the server to accomplish what you are doing.
Whether you are using the WebForms model or MVC model of ASP.NET, there are mechanisms that allow you to bind to data without having to write out the tag yourself.
For example, in the WebForm model, you have the TextBox class which you can set the Text property on.
In ASP.NET MVC, there is the TextBox extension method on the InputExtensions class which allows you to pass the content of the textbox and the method will render the tag for you.
May be what you want is the HTML agility pack. You can't execute JavaScript, but you can do some DOM manipulation. Give it a try http://htmlagilitypack.codeplex.com/.
Use jQuery with jsdom for Node.js. Easiest way to manipulate DOM elements using javascript on the server-side.
The DOM is a browser specific entity. Thus, not directly available as you seek. However, you can determine just what you want to manipulate, and use either .live() or calling your jQuery code to add behavioral stuff as elements get added. As for change:
<input id='AddressSettings_txtFirstName' name='txtFirstName'
value='#firstNameValue#' size='25' type='text' class='val_required'/>
$('#AddressSettings_txtFirstName').change(function(){
// do stuff here
});
will fire when it changes for instance.
EDIT: One other option is to have the client pull the data using ajax and JSON - but that is a small shift in your method of working at present.
Well this is the answer for Java.Here and Here
Provided by some guy named John Resig. (Not sure he knows what hes talking about when it comes to JQuery...wink wink)
Now what about .Net?
This technology, ItsNat, is very similar to your desires, the bad news... is Java based.
iam into problem of reading the value of the control which i alterd using javascript
the sequence goes like this
i got the text box control by using its id
cleared the value of the text box
make the control disabled.
when i tried to retrive the value of the textbox in aspx.cs
iam still getting the old value of the text box which i actualy cleared in the javascript
kindly suggest me to over come this issue
Thanks
Disabled input controls don't get their values posted back so ASP.Net doesn't know you changed the value. You need to enable the control.
With ASP.NET Web Forms, IDs for elements get assigned automatically by the Page on the server side. It is tricky, but possible, to manipulate element values using javascript. One way to avoid this would be to use ASP.NET MVC where the HTML would be rendered as is and javascript or jquery can be easily used to "play" with the HTML elements. We need more information to help you with the details of your request.
I wish to use xml and xsl to generate controls on an asp.net page.
I currently have a asp.net content page that contains a xml control. When the page is loaded, an xml file is loaded and the required element is extracted and set as the xml control's DocumentContent and the xml control's TransformSource is set to the appropriate xsl file.
In the xsl file, I wish to use templates to create asp.net controls depending upon the contents of the xml. Is there an easy way of doing this with the xml control on the content page?
Register a namespace in your XSL so that you can put .NET server-side tags into it. Run your XSL transform against your XML. Run the result of your transform through Page.ParseControls(). This will give you a nice control hierarchy. Add the output of that function to your Controls collection (or the controls collection of your placeholder) and you're good to go.
There are LOTS of caveats to using dynamic controls in .NET, so beware.
The generated output of transform is not parsed to be added to the page as set of controls. Rather the generated output is sent to the response. Therefore you cannot apply a transform to an XML control that will generate new controls.
There may be a way to create the transform result and invoke some parsing that can be applied to the page but that would not meet your 'easy' requirement.
I don't know of any easy way to do it, but there are a few systems out there which generate the aspnet markup on the fly then send it to the aspnet runtime from a memory stream (or similar).
I think umbraco uses a system something like that, but the initial builder mechanism is probably a little more low level than an aspnet control. It might be achievable using an httpmodule or something else that gets hit earlier in the request pipeline.