I wanna change or add custom attributes in client side by jquery and check them in server side by c#
(for example add a custom attributed named "Loaded=1" to an image HTML element when the image is loaded successfully and in server side I access to this attribute through Image control Attributes Collection)
Is it possible ??
Thanks for your feedbacks
I think you have a few Page Lifecycle aspects mixed up, the attributes that you set on client side never end up on server side, unless you post them to the server. I think you should consider adding hidden fields to forms via jQuery so that when the form is posted the values arrive at the server. Then server side you'd need to interpret the posted values and turn them into attributes on the correct Image objects.
Consider something like this:
Create the following element with jQuery:
<input type="hidden" id="Image23_Loaded" name="Image23_Loaded" value="1" />
Post this to server and parse it so you know which Image object should get the Loaded attribute.
Find the Image object and add the attribute server side.
You can also use asp HiddenField control. set it's value on client side and you can access it on server side. If your HiddenField id is "hdnImage1" you can set it's value on jquery like $('#<%= hdnImage1.ClientID %>').val('1');.
Hope this help.
You may also post a JSON result object to the server using AJAX and de-serialize it to an .net object.
take a look at: https://stackoverflow.com/a/2246724/952310
you can't do that. Once the page has been transferred, the server side cannot access the page
You can however, transfer data using $.post(url,data, callback)
data can be obtained from a form or serialized array
Related
Is it necessary to write and place all controls inside
#using (Html.BeginForm())
{
// HTML Elements and HTML Helpers.
}
while using [Required] DataAnnotations ?
I am facing strange issue in MVC5 based application. The problem is that I have used one property named e.g "Credit" in model and the datatype of this property is integer and set[Required] DataAnnotations above that property.
But I haven't used Begin form. So in this case validation doesn't fire. whereas If I write BeginForm then validation works.
So, Is it necessary to place all html elements & html helpers inside BeginForm to validate controls ?
Thanks
-Nimesh.
If you want the client-side validation to work, then yes the form controls etc. need to be within a <form> tag (as generated by the HTML.BeginForm helper). Server-side validation would still work regardless of this.
Like the commenter above, I would question why you want to have controls outside a form tag in the first place. Even if you plan to submit the data back using Ajax, it's better semantic design to use a form tag, because it's clear which data items belong together, and it also makes it much easier to gather the data to submit via ajax (e.g. if you have jQuery, you can use $("#myForm").serialize() to automatically collect the values from all the controls within a form and pass that to the ajax request).
We need to validate something when we post some data to the server, right. And for posting some data to the server you will need form tag, whether you use BeginForm() or the <form> tag. You need tags inside the form those will be validated by the server.
I guess, this will give the answer to your question. Enjoy!
I would like to know how to add custom attribute to the ColumnSeries attribute of RadHtmlChart control from Telerik?
I then want to access this attribute in code behind of asp.net page to set the Value but I don't to show the value of CustomeAttribute to RadHtmlChart on the asp.net Page.
<telerik:ColumnSeries CustomeAttribute=""></telerik:ColumnSeries>
You can't. Server properties are strictly defined in the control's class and adding your own that the code will not recognize is likely to result in a server error.
If you need information on the client you can store it in hidden fields, hidden panels or inject a custom JavaScript object from the server via the ScriptManager.RegisterStartupScript() method.
Is it possible to do something like this
$("#popupForgot").append("<asp:TextBox ID='emailTextF' runat='server' Width='200px' Text='" + $.cookie("forLogin") + "'></asp:TextBox>")
I need to append an asp.net element to a div tag which will have the cookie value as it's text. I've tried with the code above and it doesn't work.
Thank you in advance
It is not possible to do this, because asp:TextBox is rendered via server-side, whereas jQuery works on client-side.
However you can render your textbox with asp:TextBox control and then you can change its value with jQuery:
$("#emailTextF").text($.cookie("forLogin"));
UPDATE
It turns out that asp:TextBox rendered id isn't equal to id parameter (used inside asp:TextBox), try this:
$("#<%= emailTextF.ClientID %>").text($.cookie("forLogin"));
JQuery is, in the end, just JavaScript code. Javascript code runs in the client's browser.
ASP tags are a server side construct; they will be converted into <input type="Text"/> fields (or something else for multi-line textboxes) before they are sent to the client's browser.
These two are completely separate concepts that can't really interact with each other (directly).
If you want to add a textbox via JQuery it can't be an ASP textbox, it needs to be an HTML textbox. If you really do need to add an ASP textbox (you don't appear to need it from what you've shown here though) then you'll need to do a postback to the server to add it. (You could do that postback asynchronously via AJAX if you wanted.)
Your code will run in the browser, this means that you asp:TextBox will not be processed by the server. So, in short, no.
You can't do this, cause ASP.NET tags processed on the server-side, before data sends to the client.
The ways is:
-add this ASP.NET control before, and change it's value by JQuery,
-if you need to add controls dynamically, use sample html tag , and get data on server from the Form.
I have a page that I need to allow a user to edit, then I parse the information into HTML and save it to a MS SQL 2008 R2 database. I need to then add this information to an announcements page from the items contained in the database.
I am using C#, so the question is how would I do this? I have a div specifically for the content. Also, is this the best way to allow a user to manage content if I cannot use a cms ( this question is not so vital as I know it is prob more complicated than I realize)?
You can use an asp:Literal control to insert the HTML on the page via the "Text" property on the server-side:
Markup:
<asp:Literal ID="litAnnouncement" runat="server" />
Code-behind:
string htmlAnnouncement = GetHtmlFromDB(); // Get the HTML however you need to as a string.
litAnnouncement.Text = htmlAnnouncement;
I would put the code above somewhere in one of the Load or Init events, either for the page or the Literal control. Of course, there are other ways to do this, but I think this is the most straight-forward given your description.
I didn't get your question completely. but if you want to save data from an HTML element into the SQL data base, then you can add a Sqldatasource control to your page, and then define it with a parameter in the source code.
I have a page with a table on it with some information. I also have an asp.net button that I use to send an e-mail with the table markup. Currently, I am regenerating the table and storing it in a string and sending that as the body of the E-mail. What I would like to do instead is use JQuery's html function to grab the table markup of the page and store that in the variable to be used the e-mail body. Can someone provide an example?
There are a good amount of ways you could construct something like this. A quick search of JQuery syntax returns the method with which you can return an elements HTML contents:
$('div.demo-container').html();
http://api.jquery.com/html/
It would be possible to construct your Javascript in a way which grabs the return call from the html() method in JQuery and stores that value in a asp:Hidden before posting your form back to the server. Your postback reference to that hidden field would then include the markup you desire.