So I have Rad Grid that contains data and I have in above the Add New Button. I want when user has permission to add to make it enable if he doses not have then its disable I search for hours for a solution and all I come is this code:
Dim cmditem As GridCommandItem = CType(gvDefCountry.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
Dim ctrl As System.Web.UI.WebControls.Button = CType(cmditem.FindControl("AddNewRecordButton"), System.Web.UI.WebControls.Button)
ctrl.Enabled = False
But every time I run the code, I'm getting this error:
"Index was outside the bounds of the array"
The view looks like:
It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.
However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.
try this
If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then
For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
Addbtn.Enabled = False
Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
btn.Enabled = False
Next
End If
Related
Is there a way to select -1 index without adding a new ListItem("", "-1",true)) from code behind like jQuery does?
Here is an example:
http://jsfiddle.net/eL8sn/
If you're binding it on Page_Load event it does a post back (AutoPostBack='True').It will simply rebind ever time the index is changed
if (!IsPostBack)
{
BindDropDownList1();
}
(or)
If the above solution dosen't work try to add an empty item as shown:
this.myDropDownList.Items.Add(new ListItem("Select...", ""));
Do you mean like this?
DropDownList1.SelectedIndex = -1;
That's how one usually does it from code-behind.
ETA: I now see what you are talking about. And I'm afraid I don't see how it can be done from server side. All you can do on the server side is control the rendering. As far as I can tell, even if you render this code:
<select id="testSelect" selectedIndex="-1">
... it still appears with the top option appearing to be selected.
It looks as if only by explicitly setting it to -1 with javascript after rendering will it appear with absolutely nothing selected. It appears as if it can't be done declaratively in HTML.
If you can find a way to write the tag in HTML so that it appears this way on load, then you could tweak the rendering in code-behind (using .AddAttribute() or similar) but if it can't be done with a declaration, it'll need javascript.
(You could of course write a jQuery snippet to change all your dropdowns to selectedIndex = -1, but you'll have thought of that!)
You can do this
string selectStr = "SELECT";
string allStr = "ALL"
ListItem allLI = new ListItem(allStr,allStr);
ListItem selectLI = new ListItem(selectStr,selectStr);
DropDownList.Items.Add(selectLI);
DropDownList.Items.Add(allLI);
//code to fill the DropDownList with the list that your query returns
DropDownList.SelectedValue = selectStr;
I have an ASP.NET page that launches a modal dialog window:
Dim sURL As String = System.Configuration.ConfigurationManager.AppSettings("PAYORS_Path") & "PayorCopy.aspx"
lnkCopy.Attributes.Add("onclick", "javascript:window.showModalDialog('" & sURL & "',null,'status:no;dialogWidth:375px;dialogHeight:550px;dialogHide:true;help:no;scroll:yes;center:yes');return false;")
The user can create new items in this modal window. When the user clicks the Close button the modal dialog window is successfully closed, but the new items created do not appear on the parent page. When the modal window is closed I would like the parent page to refresh to show the new items the user created. Currently:
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnClose.Click
Dim strjscript As String = "<script language='javascript'>self.close();</script>"
LtClose.Text = strjscript
End Sub
I have tried adding to this script:
window.opener.location.reload(true);
But then when I test I get an error that says "Unable to get value of the property 'location': object is null or undefined."
Any help would be much appreciated!
Instead of using the old modal dialog window, try jQuery Dialog because it behaves just like a modal but keeps you in the same window. Therefore it's is easily refreshed with the following code:
location.reload(true);
For more information, check out this question here at SO.
Hope it helps.
That would be because there is no 'opener' :)
Location is method of the window object so you can even treat it as global is most cases. Any of those should work:
window.location.reload(true);
or:
location.reload(true);
EDIT Yeah I just noticed where you put that script.. if it's in the click handle inside the modal..then 'window' there is really a different one - it's modal after all! Try adding it directly after the code opening modal window - the script execution will be blocked until the modal returns, so you can so something like this:
var shouldReloadPage = window.showModalDialog('" & sURL & "',null,'status:no;dialogWidth:375px;dialogHeight:550px;dialogHide:true;help:no;scroll:yes;center:yes');
if(shouldReloadPage){
window.location.reload(true);
}
return false;
This is still inside the click handler ofc, just showing in code block for easier reading.
I have a classic ASP NET page on my SharePoint site with several buttons in it:
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.Controls.Add(new LiteralControl("<br/><br/>"));
this.Controls.Add(importZIPPOTBtn);
The first click on any button is perfectly firing the event, but any further click on any button doesn't fire, I can't understand why...
Consider aadding button to form1 or container element like panel inside page.
Button importZIPPOTBtn = new Button();
importZIPPOTBtn.Click += new EventHandler(importZIPPOTBtn_Click);
this.form1.Controls.Add(new LiteralControl("<br/><br/>"));
this.form1.Controls.Add(importZIPPOTBtn);
You can verfiy in html source, unless you add this way even literal control containing lines breaks will not be rendered.
I'm going crazy about making this code to work. I got a simple link button that I add to a panel. When I click on the link, it's like something is trigger (whole page refresh and my link button disappear) but when I debug it, I never enter my DownloadItems function.
LinkButton linkTest = new LinkButton();
linkTest.ID = "ID";
linkTest.Click += new EventHandler(DownloadItems);
linkTest.Text = "Test";
In another page, everything is working great but I can't put my finger on it :s
I have a dynamically created table and in some of the cells i have an image button associated with the redBall_Click() handler
(here is the code behind)
TableCell cellOK = new TableCell();
cellOK.Style.Add(HtmlTextWriterStyle.TextAlign, "Center");
cellOK.Width = new Unit("3%");
ImageButton redBall = new ImageButton();
redBall.CausesValidation = false;
redBall.ID = id;
redBall.ImageUrl = "~/App_Themes/DotRed.png";
redBall.Click += new ImageClickEventHandler(redBall_Click);
cellOK.Controls.Add(redBall);
My problem is that the redBall_Click() method is never called (neither after the PostBack)
How can i solve this?
P.S. : I can't use a static link because every ImageButton is associated with a specific ID that i must pass to the page i call (for example as a Session object)
You have to set up the event handler within OnInt and do it every time the page is created, even during a postback. Make sure you don't have the code within a block like:
if(!this.IsPostback)
{
...
}
Have you tried putting a breakpoint in the page load method before clicking the image? I suspect this might show that the postback is happening, even if the image click handler isn't getting fired.
Is the code to create the image button also invoked during a postback? If not, the page will postback, but the image button won't exist to invoke the click handler. Sounds bizarre, but it's caught me out a few times.
I finally resolved (just yesterday).
I guess I was building my buttons too late: in the Page_PreRender (after the event was to be fired) maybe if i put the creation in Page_Load (yes, I create everything also on PostBack) it would handle the click, but I think I won't try since I found a workaround.
I'll explain for anyone who could have the same problem:
private TableCell cellOK(string id)
{
TableCell cellOK = new TableCell();
cellOK.Style.Add(HtmlTextWriterStyle.TextAlign, "Center");
Image redBall = new Image();
redBall.ID = id; // useless
redBall.ImageUrl = "redball.gif";
HyperLink hl = new HyperLink();
hl.Controls.Add(redBall);
hl.NavigateUrl = MyPage + "?id=" + id;
cellOK.Controls.Add(hl);
return cellOK;
}
and in Page_Init()
string m_QueryStringId = Request.QueryString.Get("id");
if (!string.IsNullOrEmpty(m_QueryStringId))
{
// Do something
}