I would like to add-in on my image button but somehow it's not working. How should I modify it?
Please advice. Thanks.
<asp:Button ID="btn1" runat="server" style="margin-left: 0px;" Text="Search" class="btn btn-info"
style="background-image:url('/Content/Img/Image.png')" >
onclick="Button1_Click1" Width="128px" Height="40px" />
Search Btn Image
You've added two style attributes in your code. Try using only one.
Using multiple style attributes will only apply the style mentioned in the last attribute. You can instead combine the two styles and apply them in a single attribute.
CSS styles can be separated by a ;. Since you already have that on one style, you can just append the other style to it.
Apart from that, your code contains a > in the middle, which shouldn't be there. Fixed code:
<asp:Button ID="btn1" runat="server" style="margin-left:0px;background-image:url('/Content/Img/Image.png')" Text="Search" class="btn btn-info" onclick="Button1_Click1" Width="128px" Height="40px" />
Related
Let's say I've got an asp:button on a website which I'm trying to track to count how many times it has been clicked by different users.
<asp:Button ID="SubBtn" runat="server" OnClick="Button1_Click" runat="server" Text="Sub" />
In my code behind I've got a redirect link to a different page.
I'm aware that I need to include something like
<a href="#" name="button1" onclick="dataLayer.push({'event': 'button1-click'});" >Button 1</a>
Do I need to convert my asp:button to a html button to make this work?
You need to use attribute "OnClientClick":
<asp:Button ID="SubBtn" runat="server" OnClick="Button1_Click" runat="server" Text="Sub" OnClientClick="dataLayer.push({'event': 'button1-click'});" />
You can read more about this attribute on MSDN: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick(v=vs.110).aspx
I am making some web app using ASP.net and for look of the site I am using Bootstrap. But I have this problem that I can't solve by googling
So this is the deal .. I have panel and inside I have simple textbox and button
<asp:Panel runat="server" ID="pnlCompany">
<div style="display: inline-flex; overflow: hidden; float: left">
<asp:TextBox ID="txtClient" runat="server" CssClass="text-primary"
Wrap="true" Width="300px" required=""></asp:TextBox>
<asp:Button ID="btnInsertClient" runat="server" OnClick="btnInsertClient_Click"
CssClass="btn btn-primary" data-target="#MainContent_pnlCompany_txtClient"
Text="Dodaj klijenta" />
</div>
</asp:Panel>
But my problem show up here ... Under that panel I have another panel, with Button (that works fine, it collapsing table at end of page), then I have FileUpload button and Button (btnUploadUsers) that is giving me hard time, idea of this button is to go with upload of file, but once i click it, it keeps validating textbox (txtClient) from above panel ... I am sure this button fire it's event "btn_UploadUsers_click" because once i enter data in textbox, program stop on my break point
<asp:Panel runat="server" ID="pnlImportUsers">
<div style="display: inline-flex; overflow: hidden; float: left">
<asp:Button ID="btnCompanyList" runat="server" class="btn btn-lg btn-primary"
data-target="#MainContent_pnlCompanyList" Text="Lista klijenata" />
<asp:FileUpload ID="fuUsersUpload" runat="server" Enabled="false"
CssClass="btn-group-vertical" />
<asp:Button ID="btnUploadUsers" runat="server" class="btn btn-lg btn-primary"
Text="Upload" OnClick="btnUploadUsers_Click" data-target="#MainContent_UsersId"
ValidationGroup="fuUsersUpload" />
</div>
</asp:Panel>
Let me know if I can do anything to describe this problem better, thank you
Thank you #Benni_mac_b for advice, but i figured out what was a problem, so I'll post answer in case anyone else be in this situation.
So with using Bootstrap css and js, as you can see 'required' on the form, it will always be check if has value on every post_back
<asp:TextBox ID="txtClient" runat="server" CssClass="text-primary"
Wrap="true" Width="300px" required=""></asp:TextBox>
So, as I didn't wanted my btnUploadUsers to do PostBack, simply adding
UseSubmitBehavior="false"
In my code snippet fixed my problem
I was following this tutorial:
http://www.hongkiat.com/blog/css3-on-off-button/
I would like everything the same except I would like to change:
<section>
<a rel="external" href="#button" id="button"></a>
<span></span>
</section>
to:
<section>
<asp:Button CssClass="button" id="Button3" runat="server" OnClick="Button3_Click" Text=""\uf011;"" />
<span></span>
</section>
Because of simpler adding buttons and then programming them. Everything works OK, just when I click the button it doesn't become white and the red dot doesn't become green, I guess it's because in the tutorial is button used like a link, and if I add it with visual studio it's not a link, what could I do that i woul style the button like that even if I add it with visual studio.
If you want to have a hyperlink you should use LinkButton element. Button component shows a button element. LinkButton is rendered as a hyperlink with some extra properties.
<asp:LinkButton CssClass="button" id="Button3" runat="server" OnClick="Button3_Click" Text=""\uf011;"" />
Also you can try the following code in order to have code-behind capabilities for a stanrdard a tag.
<section>
<a rel="external" href="#button" id="button" runat="server"></a>
<span></span>
</section>
Another option is using HyperLink component
<section>
<asp:HyperLink Text="" rel="external" href="#button" id="button" runat="server"></asp:HyperLink>
<span></span>
</section>
You should pay attention to anchor's id attribute. I mean, The id attributes are prepended with MainContent_ if you have not set it to be shown only with the value you gave.
There are two options for this:
Change jQuery's selector from $('#button') to $('#MainContent_button')
Change .NET settings for showing your elements without prepending MainContent_ prefix.
I am using a button as a link because when the button is pressed it opens a popup of In Line HTML using Javascript (http://www.enthropia.com/labs/ibox/):
<asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" />
However, this prevents the OnClick C# from executing when I press the button. How do I fix this?
I suggest you this code
<a href="#inner_content" rel="ibox&width=800&height=400" title="Search Non Scrum Stories">
</a>
<asp:Button ID="searchButton" runat="server" Text="Search Stories" OnClick="searchButton_Click" />
David you must separate html link and button (it's not xaml)
Alternatively, you can use LinkButton - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
Example (from the linked documentation):
<asp:LinkButton id="LinkButton1"
Text="Click Me"
Font-Names="Verdana"
Font-Size="14pt"
OnClick="LinkButton_Click"
runat="server"/>
separate the tags and put your button in as a submit button or you can do something like:
<form action="ur_popup_page" onsumit="javascriptsunction()">
<asp:Button type="submit" id="searchbutton"/>
</form>
im creating the form include below code :
<asp:TextBox ID="txtPhone" required="required" runat="server" placeholder="Phone No. (eg. 999)"
CssClass="glowStyle"></asp:TextBox>
<br />
<asp:Button ID="btnAddDriver" Text="Add" runat="server" CssClass="button" />
<br />
<asp:Button ID="btnCnclAddDriver" Text="Clear" runat="server"
CssClass="cancelbutton" onclick="btnCnclAddDriver_Click" />
</form>
when i click the "Clear" button, the required (html5) still show up.
how to disable it for Clear button only.
Add formnovalidate attribute to your cancel/clear button.
Here you can find some more information about this attribute.
Do you actually require a server control to cancel ? A simple <input type="reset"> or a small javascript code can do the job in most situations.
If not, simple add CauseValidation="false" to your button :
<asp:Button ID="btnCnclAddDriver" CauseValidation="false" Text="Clear" runat="server"
CssClass="cancelbutton" onclick="btnCnclAddDriver_Click" />
(remove suggestion as it applies to asp.net validation)
You can set the autopostback option for btnCnclAddDriver button to False. And execute your server side code (btnCnclAddDriver_Click) by Ajax.
You can clear your TextBox(s) with javascript (jQuery) :
$('txtPhone').val('');
Or Javascript :
function name()
{
document.getElementById('txtPhone').value = "";
}
Hope this help.