Control label in other page in asp.net using C# - c#

i want ask about control label or link
i have label in home page
and I want change this label content from admin page
how to control and change it?

you want a sort of content management system, try saving this label in some datasource (xml or database) and then use it where required.

More details would be good. You want to be able to have an admin page where you have an input form that allows you to set content on the home page? If so, there are a few ways to do that. One way is to use a database to store the content, and then load from database on the home page. Another way is to store data in the HttpContext object, this however is not persistent.

You'll want to the display text from some sort of dynamic source, such as a database, xml file, flat file, etc. In the admin page, you write to that data source and load the text for the source from that source as well.

Related

Can I retrieve an item that was added via the Page Editor in the codebehind of my page? (Sitecore, C#)

I'm new to Sitecore and in the codebehind of my page, I'm setting values for Google analytics based on the information that I have for a previously designed page (I can't change the basic structure of these pages). Most of the fields I need are set in Sitecore in the Content Editor, so I can access them via
Sitecore.Content.Item.Fields["fieldname"]
However, one thing I need is the URL of the logo image on each page, which is inserted with the Page Editor. Is it possible for me to get Page Editor objects on the page in the codebehind?
Google Analytics is client-side; consider using client-side script to retrieve the value of the logo URL. To do that, your script will need to execute after the page has loaded.
If you're using jQuery, you could do something like this
jQuery(document).ready(){
var logoUrl = jQuery('.logo').attr("src");
}
I'm assuming by Page Editor you mean the Design view. If so, click the Source button to view the markup and find the control that contains the URL. Give that control a unique ID and make sure it has the runat="server" attribute. After that, you will be able to access that control in the code behind by using Me.<uniqueID>.
No, Page Editor (Experience Editor) works with JavaScript to change anything on page. Then changes that were made on page are transferred to server and applied there, but it is not relate to codebehind of your page at all. It is all is done by custom Sitecore pipelines. However after applying changes(Save button) you'll be able to access to changed field via your codebehind on page reload.
So, you have two options:
Patch Sitecore "SaveUI" pipeline and add processor to it to get changes, and do something with them.
Wait after changes are applied, page will be reloaded and you will be able to access changed field in your codebehind

How to highlight an HTML content and save it to the database as per user for future loads

I'm trying to highlight the selected text contents by the user inside the HTML page.I have highlited the text using jquery (dot net). Now I need to save some information to the database that makes me able to highlight the same contents again for future loads of the same page, taking care of all inner elements that the text could have inside.
i.e.,
Have a base HTML files thats same for every user, given the freedom to user to highlight content in provided page, after he highlites, information needs to saved to database against each user, so that when user open the same html file again,(HTML files shown in a panel) he gets the same page with the highlighing he had done earlier.
Please suggest what information should I save to database..
any pointer how would I move ahead..
Thanks in advance your help.
not a dot net expert , but it seems like you are storing content in database, when fetching they need to be highlighted.
the best way is save content as html or write you own highlight tag
and then replace it to blank when highlight not needed , and replace it with
<div style="background-color:red"> to highlight.
Hope you are getting the approch.
And if you are using HTML files , then it is always better to store them in database. String manuplation for every request will be much heavy task to do.

C# Rich textbox Append/Delete Question

I have a rich textbox which contains data loaded in from a database. I want to change the functionality of the rich textbox to ensure that data can only be written to it by a user and not deleted from it.
Of course, making the rich textbox read only won't help, nor will not enabling it. I'm stuck for ideas
With only one RichTextBox, you can't. What you have to do is instead of working with one RichTextBox, you could have two. Use one to show the data from database, and use another with editing enabled for the user to submit new data. something like how forum handle posts.
You can have the original content loaded from the database displayed in a label and have a separate textbox in which the user can add new content. On save you will concatenate the db content with the text from the textbox and save it back to the DB. This way you can only add and not remove from the original copy.

How to add html saved to a blob directly to page .aspx source

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.

Dynamic Header Of user control

I have develop a user control and i am loading it dynamically through .aspx page.
I have develop an XML and had converted it into hash table for faster searching.
The hash table contains the page name and the respective header.
I am using that hash table to load the header of .aspx page dynamically.
Now, i want that when the user control is called its header is also set dynamically by searching that hash table.
I have tried a lot but the problem which i am facing is that i am not able to trap the requested user control path at runtime.......
pls let me know if u have another solution for this...
If this XML contains HTML that should be displayed as Header, just use the Xml control.

Categories