I need a div element to cause postback to the server. I can use window.location tough but then I think I won't be able to fire any event back on the server. How can I call the asp.net generated dopostback function properly? Thx in advance
The idea is that I place a linkButton, and then I use it from the Div
<form id="form1" runat="server">
<div>
<div runat="server" ID="txtTest" style="cursor:pointer;" >Click the div</div>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" style="display:none;"></asp:LinkButton>
<br /><asp:Literal runat="server" ID="txtDebug"></asp:Literal>
</div>
</form>
and code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtTest.Attributes.Add("onclick", "__doPostBack('"+LinkButton1.ClientID+"','')");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
txtDebug.Text = "click on div";
}
Related
<dxe:ASPxButton ID="getProgram" runat="server" Text="Programs" SkinID="MenuButton" OnClick="Button_Click">
</dxe:ASPxButton>
Here is my Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
this.getProgram.Attributes.Add("Value", "View Progams Button");
}
I tried this it didn't work. Is there any other way I can achieve this?
I don't know what a <dxe:ASPxButton> is but a regular <asp:Button> has its value property set via the 'Text' attribute: -
<asp:Button ID="button" runat="server" Text="click me :)" />
I have an ASP.NET page that contains a div that displays a button. When the button is pressed the div disappears leaving just the ASP.NET page (which is itself a popup from another larger asp.net page)
The ASP.NET ASPX is here:
<div id="UpdateErrDiv" runat="server" class="msgBox" style="z-index: 2000; width: 250px" visible="false">
<div id="UpdateErrText" runat="server"></div>
<br />
<asp:Button ID="butCloseErrMsg" runat="server" CausesValidation="False" OnClick="butClose_Click" Text="Close" />
</div>
The code-behind is here:
protected void butClose_Click(object sender, EventArgs e)
{
UpdateErrDiv.Visible = false;
}
How do I close down the op-up asp.net page after the div disappears?
You would need to close the popup using Javascript. You can use something like this:
protected void butClose_Click(object sender, EventArgs e)
{
UpdateErrDiv.Visible = false;
Page.RegisterStartupScript("closeWindow", "window.close()", true);
}
I found that I cannot update the data in my second grid when I clicked on the first grid control.
There are two grids in my program and there is overloaded function GetDataTable2() to get DataTable according to the focused row in grid1.
However, I dun know why the grid2 cannot be updated.
Please help!
protected void Page_Load(object sender, EventArgs e)
{
gv1.DataSource = GetDataTable1();
gv1.KeyFieldName = "ID";
gv1.DataBind();
gv2.DataSource = GetDataTable2();
gv2.DataBind();
}
protected void gv1_FocusedRowChanged(object sender, EventArgs e)
{
gv2.DataSource = GetDataTable2((int)gv1.GetRowValues(gv1.FocusedRowIndex, "ID"));
gv2.DataBind();
}
And the asp.net:
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<dx:ASPxGridView ID="gv1" runat="server" SettingsBehavior-AllowFocusedRow="true" SettingsBehavior-ProcessFocusedRowChangedOnServer="true" OnFocusedRowChanged="gv1_FocusedRowChanged" >
</div>
<div>
<dx:ASPxGridView ID="gv2" runat="server" >
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
I think that if you set the ASPxGridView's EnableCallbacks property to false, your code will start working properly. This is the recommended way of using ASPxGridView when it is located within the MS UpdatePanel.
You don't need the UpdatePanel.
In the first grid, use the "RowClick" client side event and perform a callback in the second grid.
ClientSide Event
function gv1_RowClick(s, e) {
gv2.PerformCallback("UPDATE_SECOND_GRID|" + gv1.GetRowKey(e.visibleIndex));
}
ServerSide Event
protected void gv2_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
{
string[] args = e.Parameters.Split('|');
if (args == null || args.Length == 0)
return;
if (args[0].Equals("UPDATE_SECOND_GRID")) {
//your code with args[1] (key of the first grid)
gv2.DataSource = GetDataTable2();
gv2.DataBind();
}
}
i have a homepage and it has a iframe..i want that after clicking the button sign in..the particualr iframe will have the user.aspx..but how to implement this in code behind of the user.aspx.cs on buttonclick?? i want work it for server side...and i have learnt that javascript function can't be used as i am wanting it in server side..
my asp button and iframe in home.aspx
<asp:Button runat="server" ID="signin" CssClass="signinbt" Text="Sign in" OnClick="signin_Click"/>
</div>
<iframe id ="iframestyle" src="homeframe.aspx" name="iframe_a" runat="server" style="margin-top:0px;width:100%;height:500px;"></iframe>
</div>
my codebehind
protected void signin_Click(object sender, EventArgs e)
{
iframstyle.Attributes["src"] = "userpage.aspx";
}
here showing that iframestyle doesn't contain in the present context..
try This
protected void btnChange_Click(object sender, EventArgs e)
{
iframestyle.Attributes["src"] = "homeframe.aspx"
}
I would like to add a double click mouse event to a listbox. When I double click an item I'd like to get the specific item and assign a method.
I have been searching for tuturials in this field, but tried but somehow wasn't working.
Thank you for helping !
This code works for me
protected void Page_Load(object sender, EventArgs e)
{
if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "event 1")
{
// code for the event
}
ListBox1.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(ListBox1, "event 1"));
}
<%# Page Language="C#" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e){
if(Request.Params["ListBox1Hidden"] != null
&& (string)Request.Params["ListBox1Hidden"] == "doubleclicked" {
//This means It was double click
Response.Write("Double Click was fired selected item is "
+ ListBox1.SelectedItem.Text);
}
}
void Button1_Click(object sender, EventArgs e) {
Response.Write("Button was clicked");
}
</script>
<html>
<head>
<script language="javascript">
function ListBox1_DoubleClick() {
/* we will change value of this hidden field so
that in
page load event we can identify event.
*/
document.forms[0].ListBox1Hidden.value = "doubleclicked";
document.forms[0].submit();
}
</script>
</head>
<body>
<form runat="server">
<div>Double click on Listbox
<br />
<asp:ListBox id="ListBox1"
ondblclick="ListBox1_DoubleClick()" runat="server">
<asp:ListItem Value="1">One</asp:ListItem>
<asp:ListItem Value="2">Two</asp:ListItem>
<asp:ListItem Value="3">Three</asp:ListItem>
<asp:ListItem Value="4">Four</asp:ListItem>
</asp:ListBox>
<input type="hidden" name="ListBox1Hidden" />
</div>
<div>click on button
<br />
<asp:Button id="Button1" onclick="Button1_Click"
runat="server" Text="Button"/>
</div>
</form>
</body>
</html>
Simple sample to send selected item on a listbox:
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string test = listBox1.SelectedItem.ToString();
}