I have a html control like
<input id="Button1" type="button" value="button" />
<input id="Text1" type="text" />
<img alt="" src="" id="img1" />
i want to set its tooltip or tittle in codebehind .
I tried the following code but its not working
Button1.Attributes["tittle"] = "i am button";
Text1.Attributes["tittle"] = "i am text";
img1.Attributes["tittle"] = "i am image";
this is not working please help
Set runat="server" for each control:
<input id="Button1" runat="server" type="button" value="button" />
Then in CodeBehind in Page_Load use this:
Button1.Attributes.Add("title", "i am button");
You need to mark those elements as runat="server" so that the server knows about them. Otherwise, server-side code won't be aware that they exist.
Alternatively, you could add a blob of javascript to the response message body and have the JS set the attributes. That's silly and ugly, though.
Related
I have a search textbox that I tried wrapping in a form element:
<form id="searchForm" method="GET" action="Search.aspx">
<input name="term" type="text" id="searchTerm" class="nav-search" size="30" />
<input type="submit" value="submit" style="display:none;"/>
</form>
I can't get it to redirect to the content page (Search.aspx) with the query string (term) from the Master Page.
I tried wrapping it in an ASP:Panel and using the DefaultButton Property but that wouldn't call the Click event in code behind.
I'm perplexed as I've searched for a solution for hours and this seems like a such common task. Thanks.
Change your code to this
<input name="term" type="text" id="searchTerm" runat="server" class="nav-search" size="30" />
<asp:Button ID="searchsubmit" OnClick="searchsubmit_Click" runat="server" Text="Search" />
in Site.Master.cs add something like this
protected void searchsubmit_Click(object sender, EventArgs e)
{
Response.Redirect("~/search.apsx?content=" + searchTerm.text);
}
This will allow to search with button click, if you want to hide it, add also panel around first code, saying that this is a button to automatically press when enter is pressed Something like this:
<asp:Panel ID="UserPanel" runat="server" DefaultButton="searchsubmit">
Bootstrap login form is below:
<form class="form-vertical login-form" runat="server" action="~/Default.aspx">
<label class="control-label visible-ie8 visible-ie9">User Name</label>
<input class="m-wrap placeholder-no-fix" type="text" placeholder="UserName" name="username"/>
<label class="control-label visible-ie8 visible-ie9">Password</label>
<input class="m-wrap placeholder-no-fix" type="password" placeholder="Password" name="password"/>
<button type="submit" class="btn green pull-right" aria-pressed="undefined">
Log In <i class="m-icon-swapright m-icon-white"></i>
</button>
</form>
When the button is clicked, I want to create the connection to the database. So, I need to have sth like this:
protected void (ButtonName)_Click(object sender, EventArgs e)
{
string connStr = "Initial Catalog=LoginCheck; Data Source=MYCOMPUTER; User id=sa; password=000000;";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
...
}
But it doesn't work like ASP.NET. If I double-click on the button when I am designing, it's not taking me to code behind. Please put me in the right direction!
In ASP.Net, you want to use Server control if you want to post back.
Most of the time, <form> tag is located inside Master Page, so you cannot style it easily.
Here is an example -
<form id="form1" runat="server">
<div class="form-vertical login-form">
<asp:Label runat="server" ID="UsernameLabel"
AssociatedControlID="UserNameTextBox"
CssClass="control-label visible-ie8 visible-ie9">User Name
</asp:Label>
<asp:TextBox runat="server" ID="UserNameTextBox"
CssClass="m-wrap placeholder-no-fix" />
<asp:Label runat="server" ID="PasswordLabel"
AssociatedControlID="PasswordTextBox"
CssClass="control-label visible-ie8 visible-ie9">Password
</asp:Label>
<asp:TextBox runat="server" ID="PasswordTextBox"
CssClass="m-wrap placeholder-no-fix" />
<asp:LinkButton runat="server" ID="SubmitLinkButton"
CssClass="btn btn-default pull-right"
OnClick="SubmitLinkButton_Click">
Log In <i class="m-icon-swapright m-icon-white"></i>
</asp:LinkButton>
</div>
</form>
But it doesn't work like ASP.NET
Your code (aka "code-behind") looks like it expects ASP.Net server controls e.g. <asp:Button runat="server" id="foo"... so it can do a Postback which is the the ASP.NET "web forms" way.
Having said that, you can try
assigning a bootstrap css class to an ASP.net server control to make it look like a bootstrap button (styling)
keep your existing HTML above handle the normal HTTP POST and not deal with server controls (and deal with request.form)
It's your choice based on what works for you. Either way the core concept is based on standard HTTP POST (html form post, asp.net web forms "postback").
Hth...
I'm quite new to asp.net and vb.net, so my apologies if I do not use the correct terminology here.
I have a database table and for each row in a returned dataset from that table I want to produce some HTML code eg:
<div>
<img src="SOURCE" />
<h1>Row1</h1>
<input type="button" />
<input type="button" />
</div
<div>
<img src="SOURCE" />
<h1>Row2</h1>
<input type="button" />
<input type="button" />
</div
What would be the best way to do this? Do I simply pull back an object with the entire data and then write a foreach loop to iterate through each row and insert a string to the page, or should I be looking to use a user control?
I guess I'm trying to make a sort of forum listing page and want to fetch all topics with a particular entry in a database and then display this list on a page with some input controls and an image. I also want to add pagination; so to show only 10 posts at any time and then be able to paginate to the next page.
Again I apologise if I've not been very clear, but I'm having a little bit of a hard time understanding the best way to tackle this.
You could use a Repeater.
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<img src="SOURCE" />
<h1>Row<%# Container.ItemIndex %></h1>
<input type="button" />
<input type="button" />
</ItemTemplate>
</asp:Repeater>
If you want any code block to be repeated. Try this code which i uses..
Sample code to display any div 3 times
<% For i as Integer = 1 To 3%>
<div>
<img src="SOURCE" />
<h1>Row1</h1>
<input type="button" />
<input type="button" />
</div> <% Next %>
I have the following html:
<html>
<body>
<form runat="server">
Name: <input type="text" name="name" />
<br />
<input type="submit" name="submit" />
</form>
</body>
</html>
How do I retrieve the value in the "name" textbox posted back to the webserver to manipulate in ASP.NET WebForms?
(I know about the ASP.NET built-in controls and the possibilities with them, but I am looking for a "clean" solution without the use of built-in ASP.NET controls)
If you can't, or don't want to use asp.net textboxes, then you can retrieve the name of a regular html textbox like this:
string nameTextPosted = Request.Form["name"];
Just note that textboxes created in this manner will not automatically persist their values across postbacks like asp.net textboxes will.
Simplest solution would be to turn it into a server-side component and access it by it's name. e.g.
<asp:TextBox Id="Name" runat="server"></asp:TextBox>
...
string name = Name.Text;
Unless you have other reasons not to use a component, you'd only be making things much more difficult on your part for no justification.
ASP.net includes Html server controls for backward compatibility for just someone like you fond of html. make your html tags server controls by adding the runat="server" and id properties and you are able to access them inside your server side code with their id.
<form runat="server">
Name: <input type="text" name="name" id="name" runat="server" />
<br />
<input type="submit" name="submit" id="name1" runat="server" />
</form>
Now after this you can control their behavior:
name.Value="Hellow World !"
You have to add id and runat="server" in each control. like this :
<input type="text" name="name" id="name" runat="server" />
Its better to use asp:TextBox like this :
<asp:TextBox ID="name" runat="server"></asp:TextBox>
On an ImageButton using the AlternateText attribute renders an alt tag to the browser.
<asp:ImageButton ID="imagebuttonStuff" runat="server" OnClick="imagebuttonStuff_Click" AlternateText="Make Stuff Happen" ImageUrl="/images/icons/stuff.png" />
<input type="image" name="imagebuttonStuff" id="imagebuttonStuff" src="/images/icons/stuff.png" alt="Make Stuff Happen" />
How do I render a title tag?
ToolTip="this is the title"