Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have created a program that runs through a flow using C#
At the moment it contains a large amount of buttons to make certain panels visible etc.
I was wondering if I could make the page refresh when the user checks a checkbox?
You need to set the CheckBox' AutoPostBack-property to true(default is false).
<asp:CheckBox id="checkbox1" runat="server"
AutoPostBack="True"
Text="Check/uncheck me for a postback"
OnCheckedChanged="Check_Clicked"/>
IF you want to refresh your panel on check of checkbox, you can do something like below:-
<asp:CheckBox id"chkVisible" runat="server" AutoPostBack="true" OnCheckedChanged="chkVisible_OnCheckedChanged" Text="Test for Page referesh" />
You need to set AutoPostBack property to True for refreshing your page.
Try this :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//do whatever you want to on first time page load
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I need to change the class of a div nested inside a gridview item template, i have given the runat="server" tag and an id for the div. How can we change the class of that particular div upon gridview databind based on each row conditions.
ASPX
<asp:GridView ID="gv" runat="server" OnRowDataBound="gv_OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div id="yourDiv" runat="server"></div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code-behind
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
HtmlGenericControl div = (HtmlGenericControl)e.Row.FindControl("yourDiv");
div.Attributes.Add("class", "ClassYouWantToAdd");
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Good morning,
I have the following asp Image and would like to add the on mouse over event, as follow:
<asp:Image ID="MapImage" runat="server" Height="601px" Width="469px" OnMouseOver="OnMouseOverMap"/>
I have also added the following method on the C# code:
protected void OnMouseOverMap(object sender, EventArgs e)
{
int i = 9;
}
I also have created the same method without the parameters but I cannot manage to call that C# function.
Can somebody help me with this issue?, How can I do to call the C# function from the ASP code.
Cheers!
There is no OnMouseOver server-side event on asp:Image object.
What you can do you can write js function called on client-side onmouseover event and inside that function trigger click on hidden button or you can change Image to ImageButton and trigger click on that image.
<asp:Image ID="MapImage" runat="server" Height="601px" Width="469px" onmouseover="javascript:foo()"/>
<asp:Button ID="Button1" runat="server" style="display:none" OnClick="OnMouseOverMap" />
And in js function:
function foo()
{
document.getElementById('<%= Button1.ClientID %>').click();
}
I am pretty sure that you are supposed to insert javascript code there and not a "code behind event handler reference". See ASP NET image onmouseover not working for example.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on an asp.net application. I need a drop downlist where user can select multiple items from dropdown. Also, the number of selections allowed should be controlled by code.
Please suggest
For that you want you could use a ListBox. You can't use a DropDownList, because a DropDownList is used for the selection of a unique option. In other words, you can't select more than one of the provided options. As it is stated here, DropDownList class
Represents a control that allows the user to select a single item from a drop-down list.
On the other hand for a ListBox class we have that
Represents a list box control that allows single or multiple item selection.
For more information about ListBox, please have a look here.
Here's a solution using jQuery:
jQuery
<script>
$(document).ready(function () {
$('#BeerSelection').change(function () {
var $BeersSelected = $('#BeerSelection').val().length;
if ($BeersSelected > 3) {
alert("Hey Bro, you've selected too many beers");
}
});
});
</script>
aspx code
<asp:ListBox runat="server" ID="BeerSelection" SelectionMode="Multiple">
<asp:ListItem>Yuengling</asp:ListItem>
<asp:ListItem>Budwiser</asp:ListItem>
<asp:ListItem>Blue Moon</asp:ListItem>
<asp:ListItem>Coors Light</asp:ListItem>
<asp:ListItem>Chimay</asp:ListItem>
</asp:ListBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit />
I suggest you use this tutorial for dropdownlist: dropdownlist tutorial, it works fine :)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to customize the webcalendar-element in asp.net with c#.net
What I would like to do: For certain users, disable the possibility to view previous months - but they should still be able to see all of the upcoming months
Is there a way to use a button-event to change to the next month?
All I've found so far is ShowNextPrevMonth == false
Thanks for your help!
Just set PrevMonthText property to an empty string e.g.:
<asp:Calendar ID="Calendar1" runat="server" PrevMonthText=""></asp:Calendar>
This will effectively hide "view previous month" button, keeping just "view next month" one, so you don't have to invent an extra button for that
If you want to do it only for certain users, you can do the same in code, e.g.
if (user == someRestrictedUser) {
Calendar1.PrevMonthText = string.Empty;
}
UPDATE
If you need to hide "Previous Month" only when user is in current month, but do show it when use is in future month here're the steps:
Still hide it originally in the markup, but also add handler for OnVisibleMonthChanged event:
<asp:Calendar ID="Calendar1" runat="server" PrevMonthText="" OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">
</asp:Calendar>
In the event handler in addition for user restriction check for calendar's month:
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
if (user == someRestrictedUser && e.NewDate.Month == DateTime.Now.Month) {
Calendar1.PrevMonthText = string.Empty;
} else {
Calendar1.PrevMonthText = "<";
}
}
This code will hide "Previous month" only for restricted user and only when user's calendar is in the current month.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an image and I want to get image url with method .I found this questions on the web.But answer not quite.
Source as follows:
<img id="largeImage" src='<%#ShowLast() %>' alt="" />
cs file as follows:
public string ShowLast()
{
using (DBMLDataContext dc=new DBMLDataContext())
{
var query = (from d in dc.News
select d).Last();
return query.Photo.ToString();
}
}
Whats happening? If you are using this inside a databound control then <%# is right. If not you will want to use <%= or better yet one of the variations that encode the output.
Based on your comments it sounds like you should just use an <asp:Image> control and then set its ImageUrl property in the codebehind.
Markup:
<asp:Image runat="server" id="largeImage" GenerateEmptyAlternateText="True" />
Code Behind:
// in page load
largeImage.ImageUrl = ShowLast();
The only gotcha I can think of with this approach is if you are using the id "largeImage" in your css or somesuch. Converting it to an asp.net control means it will take control of the ID so you will need to target it through your css with a CssClass property or if you are using a modern version of .net you also have some other options to set the ID to a static id - I'll update again if this is an issue.
You can call the method like this
<img id="largeImage" src='<%= ShowLast() %>' alt="" />
if method is returning URL in string