I'm looking to create some HTML buttons via code behind.
I currently have the following code to create INPUT buttons, but I want to be able to have some css hover over events and from what I've learnt this can't be done with INPUT buttons.
This is what I have:
Button btnRemoveFromQuarantine = new Button();
btnRemoveFromQuarantine.ID = "btnDoThis";
btnRemoveFromQuarantine.CssClass = "fa editButton";
btnRemoveFromQuarantine.Click += new EventHandler((s, e) => btnRemoveFromQuarantine_Click(s, e, ID));
This gives me:
Can anyone offer some code to create
Thanks..
Related
I have had an issue that is causing me problems.
I have an ASP Button not firing the CLICK function but it is inside a table generated in code behind and placed in a placeholder control in the html.
The table generates. The button is on screen. I click it nothing happens.
I tried several methods from writing this:
html.Append("<asp:LinkButton id=\"" + clist[i] + "\" runat=\"server\" onClick=\"Show_Click\">" + clist[i] + "<asp:LinkButton>");
the above didn't work as I stated then I tried:
newbutton.ID = "id";
newbutton.Text = "TEXT";`
newbutton.Click += new EventHandler(Show_Click);
newbutton.CssClass = "ButtonAsLink";
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
newbutton.RenderControl(htmlWriter);
html.Append(sb.ToString());
Again these generate the table...and the button is on screen. You can click it but it doesn't call the CLICK function.
I feel theres something with controls being reset or instanced but I am not sure what could I get any advice please regarding how to create a asp button, place it in a table generated in code behind, add to a placeholder control in html page ?
I want to add dynamically button in html table.
I created a master page and another subpage.
On the sub page, I want to dynamically add a button in html table.
This is my code:
Button btnSend = new Button();
btnSend.ID = "btnSend";
btnSend.Text = "Send";
btnSend.Click += new System.EventHandler(btnSend_Click);
this.form1.Controls.Add(btnSend);
But I get an error:
form1 is not accessible from sub page.
Please help me to dynamically add a button into the html table.
If you use asp.net then you have no forms. So simply insert a button from the toolbox and set buttonName.visible = true or false as you need.
If you want to add dynamic controls to your sub page, then i suggest you to add a panel, and then simply use panel.controls.add(your button) and thats all.
Do you create the HTML table on codebehind? If so, you may add the button there.
If not, you may try putting a Literal there, and fill it with the code for an HTML button if needed.
So I am looking for a way to add HTML text to a programmatically created button, or some other control that would accept HTML text and have a on_click_event to capture.
I have a table that I am building dynamically in the codebehind file based upon steps (attendance to a lesson, and the taking of a quiz) that are recorded as complete or incomplete in the database. If a step was not done, I entered a button with a simple X
If the step was done, I just added HTML month and day to the cell.
Attendance to the lesson is a step that can be repeated, so I wanted to make the lesson button look like the styling of a completed quiz, but still capture a 2nd+ attendance point with a click_event.
I am stumped in making a dynamically created button work with my HTML styling. My text style on an ASP.net webcontrol button in a codebehind file is being interpreted as literal text on that button.
Here is the code that fills the cells, either creates the buttons, or adds the text
if(lesson_completed == true)
{
DateTime date = Convert.ToDateTime(lesson);
Button markNewDateComplete = new Button();//System.Web.UI.WebControls.Button Class
markNewDateComplete.Text = "<font style='font-size:50%;color:silver;'>" + date.ToString("MMMM") + "</font><br><font style='color:light gray'>" + date.ToString("dd") + "<font>";
markNewDateComplete.CssClass = "mybtn";
markNewDateComplete.CommandName = lesson_detail_id.ToString();
markNewDateComplete.Click += new EventHandler(this.NewDateLesson_Click);
tc2x.Controls.Add(markNewDateComplete);
}
else
{
DateTime date = Convert.ToDateTime(quiz);
tc2x.Text = "<font style='font-size:50%;color:silver;'>" + date.ToString("MMMM") + "</font><br><font style='color:light gray'>" + date.ToString("dd") + "<font>";
}
Here is what the output looks like on-screen
There are many pages in SO that give insight how to do this in the regular ASPX page, but none that I could find to do this programmatically in a ASPX.cs codebehind file.
In programming there is always another way to do something; so I am looking for a way to add HTML text to a programmatically created button, or some other small control that would accept HTML text and have a on_click_event that I could use as a method back to SQL.
Example of what I want, but this is not for the codebehind file.Font awesome inside asp button
I am making an asp.net web application which has to play videos. In my start page I have a hyperlink for each video. All the hyperlinks are identical, except their names. This Means they all link to the same page. Im interrested in knowing wether there is an option to know which hyperlink was clicked. I would like to retrieve the name of the hyperlink.
My code for generating the hyperlinks looks as follows:
foreach (FileInfo i in corFiles)
{
HyperLink t = new HyperLink();
t.Text = i.Name;
t.NavigateUrl = "page.aspx";
CorrectArray.Add(t);
}
return CorrectArray;
The text of the hyperlink is Unique to a video, which Means I can change the src destination of the video to play based on the text name. So the question goes as follows. Are there any way of retrieving the text name of the hyperlink when it is clicked by the user?
I hope you can help! Thanks in advance.
Regards
Magnus
You can add a link buttons instead of hyper links, if you want to make a post back to the same page.
foreach (FileInfo i in corFiles)
{
LinkButton t = new LinkButton();
t.Text = i.Name;
t.Click += new EventHandler(DynamicClick);
t.CommandName = i.Name;
CorrectArray.Add(t);
}
void DynamicCommand(Object sender, CommandEventArgs e)
{
// using e.CommandName and e.CommandArgument you can differentiate the hyperlinks
}
If i understood your question,
you have to add the name attribute in the hyperlink tag and get its values in the code behind by fetching names
You can use JQuery that is integrated into .NET to get the text of the hyperlink upon it is clicked by the user. To be able to access the Hyperlink's text from Javascript simply add it to a custon tag inside the link to have something like this <a href="page.aspx" htext="hyperlink text">. As the hyperlink html is generated from .NET server side code you have to generate this custom tag from the .NET server side context.
Why don't you use a Querystring?
t.NavigateUrl = "page.aspx?video=<someid>"
and in the page you parse the querystring to show the correct video?
I am starting a new asp.net web app class (using c#). For my first lab I need to create a simple web page with a couple button. I have already made the page with the buttons and text. When you press the button it needs to change the text color using in-line css. How would I go about adding the in-line css to the button. Would I add some sort of C# code in the button to enable css? I am quite confused how to add the css to the web app. Any ideas?
From your question it sounds like you want to add inline css to some sort of element containing text when you click a Button?
protected void btn_Click(object sender, EventArgs e)
{
string inlineCss = "your css goes here";
//I'm assuming the text you want to apply css to is a Label with ID=label
label.Attributes.Add("style", inlineCss);
}
Try this on click event
HtmlLink css = new HtmlLink();
css.Href = "css/fancyforms.css";
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
If needs inline
txtmyCtrl.Style.Add(HtmlTextWriterStyle.Color,"#33cc45");