ModalPopUp Displaying after LinkButton Postback - asp.net

After spending hours on it i still couldnt find the Solution,Plaese Help.
I am Developing a Website where I have a Gridview with data,i have a linkbutton as a templatefield in one of the Columns which onClick is doing a postback and displaying the records in a modalpoupextender,which is inside a seperate asp panel,
i have edit,update,delete buttons in that popup which are doing postback and functioning well.
Remmember i have not used UpdatePanel anywhere,as i do not have that kind of requirement.
Now,i have another LinkButton on the Page(not in gridview),which has some other functinality after OnClick postback,the problem is When i Click That LinkButton it first displays the ModalpopUp and then it does the postback and completes the function.The important part is that the Modal PopUp disappears just in seconds.
So,i just get a glimpse of Modalpopup whenever i click on the LinkButton.
I tried ModalPopUpExtender1.hide() at every Possible Place,but its not Working.
I am not sure how to disable that popup from appearing on LinkButton Click.Please Help me on it.I am in Trouble.
Thanks in Advance.
Here is my GridView Code:
<asp:GridView ID="dg_Task" runat="server" CssClass="gridview"
BorderWidth="1px"
Font-Names="Trebuchet MS" Font-Size="Small" AllowSorting="True"
AutoGenerateColumns="False" onrowdatabound="dg_Task_RowDataBound"
Width="100%" Height="143px"
onprerender="mergeDoc">
<Columns>
<asp:TemplateField HeaderText="Task">
<ItemTemplate>
<asp:Label ID="lbl_tid" runat="server" Text='<%#Bind("ID") %>'
Visible="False"></asp:Label>
<asp:LinkButton runat="server" ID="Lnk" ForeColor="Black"
CommandArgument='<%# Bind("ID") %>' Font-Underline="False" onclick="Title_Click"
Text='<%# Bind("Task") %>' Font-Names="Trebuchet MS"></asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="35%" />
<ItemStyle Height="2px" HorizontalAlign="Left" VerticalAlign="Top" />
</asp:TemplateField>
Here is The CodeBehind:
protected void Title_Click(object sender, EventArgs e)
{
ddown_status.Items.Clear();
var btnId = sender as LinkButton;
string id = btnId.CommandArgument;
btnUpdate.CommandArgument = id.ToString();
btnDelete.CommandArgument = id.ToString();
//Some Code which fills the details of my PopUp Fields
this.modalPopUpExtender1.Show();
}
Here is the another LinkButton(On Main Page) code:
protected void LinkButton1_Click(object sender, EventArgs e)
{
//here even i simple postback(Without any code) Triggers The PoPUp and Provides a Glimpse then the rest code runs
//sample code here
}
Please Help .Thanks

Related

Adding buttons in DataRow in DataTable

I have dynamically created DataTable to bind the GridView. I have two buttons, their visibility is set to false. I want when I add a new row on button click I want one of the buttons to be set visibility=true in that new row, and the other one button to stay visibility=false. So the button should be visible only for the row which the user adds, not visible in all rows in DataTable. Here is my code, I don't have any idea how to fix this. Please help
Markup:
<asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView2_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button189" Visible="false" OnClick="Button189_Click" runat="server" Text="odzemi svez vrganj" />
<asp:Button ID="btnTest" Visible="false" runat="server" CommandName="odzemi" CssClass="button2" OnClick="btnTest_Click" Text="-" Width="100px" Font-Bold="True" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code behind:
protected void Button5_Click(object sender, EventArgs e)
{
MethodForAddFirstRow();
//Here i need somehow to set bnTest to be visible only for this row,other button to stay invisible
}
protected void Button5_Click(object sender, EventArgs e)
{
MethodForAddSecondRow();
//Here I need somehow to set Button189 to be visible only for this row,other button to stay invisible
}
In order to handle events of buttons inside grid you need to use OnRowCommand so you need to update your grid to be like the following
<asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView2_RowDataBound" onrowcommand="gv_RowCommand">
and make sure that each button has CommandName attribute like the following
<asp:Button ID="Button189" Visible="false" OnClick="Button189_Click" runat="server" Text="odzemi svez vrganj" CommandName="Command1" />
<asp:Button ID="btnTest" Visible="false" runat="server" CommandName="Command2" CssClass="button2" OnClick="btnTest_Click" Text="-" Width="100px" Font-Bold="True" />
then create the following event handler inside the code behind
void gv_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if(e.CommandName=="Command1")
{
}
else if(e.CommandName=="Command2")
{
}
}
In order to access buttons inside the rowcommand event handler you can use the following
GridView customersGridView = (GridView)e.CommandSource;
GridViewRow row = customersGridView.Rows[index];
Button btn = (Button)row.FindControl("Button189");
btn.Visible=false;

How to delete a row in a dynamically generating grid view?

Hello Respected sirs,
I am generating a shopping cart like ordering system, in which i add/bind the productname, productprice, and productquantity from DataTable to GridView.
I have Added an ImageButton to the gridview only for deleting the selected row.
I also know that we can not delete a row from a dynamically generated grid view. so i placed a code in the ImageButton Click event that deletes the row from DataTable (Which is STATIC during the whole process) and again binds the Data With GridView.
Please note that i hv already once bind the data with gridview in my "BTN_ADD TO CART_Clicked".
Here is my code snippet,
protected void gvorderlist_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int index = Convert.ToInt32(e.CommandArgument);
DataRow row = dt.Rows[index];
dt.Rows.Remove(row);
gvorderlist.DataSource = dt;
gvorderlist.DataBind();
}
}
and ASP code is,
<asp:GridView ID="gvorderlist" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5"
onpageindexchanging="gvorderlist_PageIndexChanging"
onrowcommand="gvorderlist_RowCommand">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Cancel Order" ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImgbtnCancelOrder" runat="server" CausesValidation="false"
ImageUrl="~/images/cross.PNG" OnClientClick="Javascript: return confirm('Aap Chutiye hai');" CommandName="Delete"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
I am getting an Error which says : The GridView 'gvorderlist' fired event RowDeleting which wasn't handled.
Any help will be appreciated...
Thank You
The error explains everything. You need todefine the event method for OnRowDeleting in markup:
<asp:GridView ID="gvorderlist" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5"
onpageindexchanging="gvorderlist_PageIndexChanging"
onrowcommand="gvorderlist_RowCommand" OnRowDeleting="gvorderlist_RowDeleting">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Cancel Order" ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="ImgbtnCancelOrder" runat="server" CausesValidation="false"
ImageUrl="~/images/cross.PNG" OnClientClick="Javascript: return confirm('Aap Chutiye hai');" CommandName="Delete"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And add an empty method in the code:
protected void gvorderlist_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
// No need to implement code here
}
The attributes for the GridView are case-sensitive, so change onrowcommand to OnRowCommand and see if that fires when you click the delete button. If not, you'll need to define OnRowDeleting explicitly. (Also change the capitalization of onpageindexingchange)
Give Command Name=D instead of Delete. It searches for Row_Deleting event when Command Name =Delete.

How to fetch the Value of a LinkButton in a GridView Template Field

I Have a LinkButton In a TemplateField In a GridView. The LinkButton is bound to database which shows the time save in database.All I want is to fetch each linkbutton time value and compare it to current time and if linkbutton time is less than current time ,make it disable.
Any pointers will be helpful.
Thanks in advance.
<asp:GridView ID="grdview" AutoGenerateColumns="false" runat="server" OnRowCommand="grdview_RowCommand">
<Columns>
<asp:BoundField DataField="AudiName" DataFormatString="Audi {0}" HeaderText="Audi Name" />
<asp:TemplateField HeaderText="StartTime">
<ItemTemplate>
<asp:LinkButton ID="lnkmovietime" runat="server"
Text='<%# Eval("StartTime") %>'
CommandName="time"
CommandArgument='<%#Eval("AudiID") %>'>
</asp:LinkButton>
<asp:HiddenField runat="server" ID="hf1" Value='<%#Eval("StartTime")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
You can use the OnRowDataBound event to hook into the data binding and disable the button.
Form
<asp:GridView ID="MyGridView"
OnRowDataBound="MyGridView_RowDataBound"
runat="server">
....
</asp:GridView>
CodeBehind
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Find the button
var linkButton = (LinkButton) e.Row.FindControl("MyLinkButton");
// Toggle enabled/disabled based on time
// Using the button text is probably a bad idea, but is used here for demonstration purposes
linkButton.Enabled = (Convert.ToDateTime(linkButton.Text) > DateTime.Now);
}
}
The code above has not been tested, but should give you an idea of how you can approach this.
You can set the Enabled property of LinkButton comparing with the current time:
<asp:LinkButton ID="lnkmovietime" runat="server"
Text='<%# Eval("StartTime") %>'
Enabled = '<%# ((DateTime)Eval("StartTime")< DateTime.Now )? false : true %>'
CommandName="time" CommandArgument='<%#Eval("AudiID") %>'>
</asp:LinkButton>

How to access "textChanged" event from text box that added to telerik Rad Grid?

Hi There Do you know how to access textboxes textChanged event added to a radgrid that are bound but are used to trap any row related input a user typed in to the textbox for that column. I need to access this data server side when a postback occurs. Your thoughts are greatly appreciated Thanking you
Being in a RadGrid really doesn't change much. Set AutoPostBack="true" on the TextBox, and create an OnTextChanged event handler:
<telerik:RadGrid ID="RadGrid1" runat="server">
<MasterTableView AutoGenerateColumns="false">
<Columns>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged" />
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
In code-behind:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox txt = sender as TextBox;
if (txt != null)
{
//some logic here
}
}

EditTemplate property of asp:GridView control

I have a asp:GridView and in there i have two columns , in one column i want to show label
but when i click an sdit button i want to show a drop down list in that particular column,
i have created the grid view like following:
<bw:GridView ID="grdProducts" AllowPaging="True" PageSize="5" AllowSorting="True"
CssClass="DGTable" runat="server" AutoGenerateColumns="False" DataKeyNames="LinkedProductCode"
RowSelectingEnabled="True" RowStyle-CssClass="DGItem" SelectedRowStyle-CssClass="DGSelectedItem"
FooterStyle-CssClass="DGFooterTR" EditRowStyle-CssClass="DGEditItemValidator" >
<Columns>
<asp:BoundField DataField="LinkedProductCode" HeaderText="Product Code" ReadOnly="true" meta:resourcekey="BoundFieldResource4" />
<asp:TemplateField HeaderText="Product Type" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label ID="lbl1" runat="server" Text='<%# Bind("LinkedProductType")%>' />
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="linkedproductList" runat="server" DataSourceID="list">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle CssClass="DGSelectedItem" />
<PagerStyle CssClass="DGPagerTR" />
<HeaderStyle CssClass="DGHeaderTR" />
</bw:GridView>
what should i do to do it? What should i write in edit button's click event?
Please help..
It depends on how you are setting up the Edit button. If you have
<asp:Button ID="btnEdit" CommandName="Edit" runat="server" Text="Edit" />
within an <ItemTemplate> in the GridView, then the Gridview will automatically go into Edit mode when the Edit button is clicked. The CommandName Edit is a special CommandName to put a GridView into edit mode.
If you wanted to implement some specific behaviour in edit mode, then this can be achieved by setting up an OnRowEditing event handler and implement your logic here. This would look something like this
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
// Set editing on the row that raised the event
GridView1.EditIndex = e.NewEditIndex;
/* Insert specific editing logic here */
GridView1.DataBind();
}
You only need to create a ButtonField with Commandname set to "Edit" (alternatively, set the AutoGenerateEditButton property of the GridView to True).
The GridView supports preconfigured commands for fields that specify a specific set of CommandNames (such as "Edit", "Delete", "Cancel").
When this button is clicked, your GridView will go into "Edit" mode and the EditItemTemplate will automatically be displayed.

Resources